James Thanks! I have some code to do it (but it is old code and doesnt seem to work anymore) so I figured I would ask this list :-)
I will give this routine a whirl and see how it goes. Reviewing the code, what does $2 (path) and $5 (point to data to post) contain? Do you have a calling example? Regards Michael S. Erickson [email protected] On Sep 1, 2010, at 9:06 AM, James Wright wrote: > Mike, > > Some kind person gave me this code: > > ` (PM) HTTP_SendRequest > ` Performs the actual HTTP request > ` $1 - URL > `$2 - Path > `$3 - request method GET/POST > `$4 - pointer to response blob > `$5 - point to data to post > C_TEXT($1;$host) > C_TEXT($2;$path) > C_TEXT($3;$requestMethod;$headers;$path;$crlf;$options) > C_POINTER($4;$response) > C_LONGINT($0;$error;$socket;$timeoutAt;$bytesSend;$position) > C_BLOB($data) > C_POINTER($5;$http_data) > $host:=$1 > $path:=$2 > $requestMethod:=$3 > $response:=$4 > $error:=-1 > $http_data:=$5 > $http_timeout:=60 `a minute > > $pos:=Position(":";$host) > If ($pos>7) > $host:=Substring($host;1;$pos-1) > $port:=Num(Substring($host;$pos+1;32000)) > Else > $port:=80 > End if > ` Clear the response blob > SET BLOB SIZE($response->;0) > > ` If we have a GET request append the data as request parameters > If (($requestMethod="GET") & (BLOB size($http_data->)>0)) > $path:=$path+"?"+BLOB to text($http_data->;Text without length ) > End if > ` Build the HTTP headers > $crlf:=Char(Carriage return )+Char(Line feed ) > $headers:=$requestMethod+" "+$path+" HTTP/1.1"+$crlf > $headers:=$headers+"User-Agent: 4D HTTP Client"+$crlf > $headers:=$headers+"Host: "+$host+$crlf > $headers:=$headers+"Accept: */*"+$crlf > $headers:=$headers+"Connection: close"+$crlf > ` For a POST request we need to add a content-length header > If ($requestMethod="POST") > $headers:=$headers+"Content-Length: "+String(BLOB size($http_data->))+$crlf > $headers:=$headers+"Content-Type: application/x-www-form-urlencoded"+$crlf > End if > ` Important: the headers must end with a blank line > $headers:=$headers+$crlf > ` Convert the headers to a blob > TEXT TO BLOB($headers;$data;Text without length ) > ` For a POST request we append the data to the headers > If ($requestMethod="POST") > COPY BLOB($http_data->;$data;0;BLOB size($data);BLOB size($http_data->)) > End if > > $error:=TCP_Open ($host;$port;$socket;0) > ` If we have a connection > If ($socket#0) > ` Send the request > $bytesSend:=TCP_SendBLOB ($socket;$data) > $state:=TCP_State ($socket) > $timeoutAt:=Milliseconds+($http_timeout*1000) > SET BLOB SIZE($data;0) > $state:=TCP_State ($socket) > Repeat ` Get the response (wait until the connection is closed) > If (TCP_ReceiveBLOB ($socket;$data)=0) > COPY BLOB($data;$response->;0;BLOB size($response->);BLOB size($data)) > Else > DELAY PROCESS(Current process;1) > End if > Until (BLOB size($data)>0) | (Milliseconds>$timeoutAt) > ` Close the connection > $error:=TCP_Close ($socket) > ` Strip the HTTP headers from the response > $headers:=BLOB to text($response->;Text without length ) > $position:=Position($crlf+$crlf;$headers) > If ($position>0) > $error:=0 > $position:=$position+4 > DELETE FROM BLOB($response->;0;$position-1) > End if > End if > $0:=$error > > > Best > > James. > > > Drag+drop Ltd > Suite 6 Chichester House, 45 Chichester Road, Southend-on-Sea, Essex, > England, SS1 2JU > www.draganddrop.co.uk • [email protected] > +44 (0) 1702 616895 • +44 (0) 8000 432212 > Reg no. 04203263 > > > On 1 September 2010 16:26, Mike Erickson <[email protected]> wrote: >> >> Hey Gang >> >> I have a need to send some HTTP requests to another site and am curious if >> this is possible with native A4D of anybody has some code they would be >> willing to share to do this. It can be a 4D method (I will execute the >> code within the database) or A4D script call. >> >> Regards, >> >> Mike Erickson >> Automated Solutions Group >> [email protected] >> _______________________________________________ >> Active4D-dev mailing list >> [email protected] >> http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev >> Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/ > _______________________________________________ > Active4D-dev mailing list > [email protected] > http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev > Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/ _______________________________________________ Active4D-dev mailing list [email protected] http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/
