|This class is used for sending "GET" and "POST" HTTP requests. Use the following code to test it:|
oHttp = CreateObject("THttpRequest")
? .Status, .StatusText
? "Response length:", .ResponseLen
* ? .GetResponseHeader("content-type")
MODI FILE response.txt NOWAIT
Custom WinHTTP HttpRequest class (WinHTTP)
|Nov. 2, 2003: code completely rewritten.|
List of HTTP Status Codes on MSDN.
Post FoxPro Data to Your Web Server with WinInet written by Rick Strahl and published in April 1998 issue of FoxPro Advisor.
* * *
Here is a simple example of using this class to exchange information between VFP application and ASP.Net page. Two pieces of code, VFP and .Net, are required. VFP part posts HTTP Request stuffed with some data. C# part extracts data from the request, processes it and sends back a response.
Create ASP.Net Web application and call it SendRequest. Add new web form and call it ExchangeData.aspx. Both names are optional, though the complete name of the page (URL) must be provided to the VFP part.
Remove all HTML code from the web form. It is not going to be used anyway; moreover it may affect sending HTTP response headers. Open the code part (C#) and add the following method to ExchangeData class.
private void ProcessRequest()
//read HTTP Request header
string sender = Request.Headers["Request_Sender"];
//convert body of HTTP Request to array of bytes...
System.IO.Stream s = Request.InputStream;
byte buffer = new byte[(int) s.Length];
s.Read(buffer, 0, (int) s.Length);
//...and then to string
ASCIIEncoding enc = new ASCIIEncoding();
string b = enc.GetString(buffer);
//send back data as HTTP Response header
"Dear " + sender +
"! Your request has been received at " +
DateTime.Now.ToString() + ".");
//send back data as HTTP Response body
Response.Write("Request received: " + b);
Call ProcessRequest from Page_Load method of the web form. Compile .Net SendRequest project.
Then create a VFP part for sending requests and obtaining responses from ASP.Net page. As I said, this part must include URL for the webpage. The local server is used for simplicity.
SET PROCEDURE TO HttpRequest ADDITIVE
LOCAL oHttp As THttpRequest
oHttp = CREATEOBJECT("THttpRequest")
WAIT WINDOW NOWAIT "Sending HTTP Request..."
oHttp.Send(FILETOSTR("config.fpw")) && body
? .status && returns "200"