Get PostData

From CometWiki

Jump to: navigation, search

XAP Control: Get PostData

When issued to LUN 0 in an XAP program, the "Get PostData" control gets the post data that was passed from the browser. PostData may be very large if it contains one or more files selected.

Syntax:

output$ = Control( 0, "Get PostData" )

Return Value:

String containing the post data from the browser

Example -- Transferring one or more files from browser to xap:

Html page that sets up the transfer:

<form action="http://signature.net:8080/xap/p1"
enctype="multipart/form-data" method="post">
<p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<p>
Please specify a file, or a set of files:<br>
<br><input type="file" name="file1" size="40">
<br><input type="file" name="file2" size="40">
<br><input type="file" name="file3" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>

Program that receives the result:


!//IB// Obj(p1,xap) 

length dynamic & local postdata$ separator$ line$ section$ body$
length 16.0 & local i section seplen
	clear

	postdata$ = Control( 0, "Get PostData" )

	Print '<p>Program P1 Active'
	i = len(postdata$)
	print '<p>length of postdata is ';i
	seplen = pos('@0d@',postdata$)-1
	print '<p>separator length ';seplen
	separator$ = sub(postdata$,1,seplen)
	print '<br>separator=';separator$
	postdata$ = sub(postdata$,seplen+2,len(postdata$))
	do
		!separate each section
		i =  pos(separator$,postdata$)
		section$ = sub(postdata$,1,i-1)

		if i = 0 goto done
		section = section + 1
		print '<p>Section ';section
		postdata$ = sub(postdata$,i+seplen+1,len(postdata$))

			! separate each line
			do
				i = pos('@0d@',section$)
				if i = 1 goto body
				line$ = sub(section$,1,i)
				print '<br>line=';line$
				section$ = sub(section$,i+2,len(section$))
			loop
body:
			body$ = sub(section$,3,len(section$)-4)
			i = len(body$)
			print '<br>body len = ';i
		! put the body in a file
		erase 'body.txt', dir='tmp' noexcp
		create 'body.txt', dir='tmp' noexcp
		close(10) & open(10)'body.txt', dir='tmp' noexcp
		printfile(10)body$
		close(10)

	loop

!*** Program Termination
!
done:
 close
 stop

Personal tools