Send Method

 

Description

 

Sends an HTTP request to an HTTP server.

 

C/C++ Syntax

 

HRESULT Send(

VARIANT varBody

);

 

PowerBASIC Syntax

 

METHOD Send (OPTIONAL BYVAL vBody AS VARIANT)

 

Parameter

 

vBody

[in, optional] Data to be sent to the server.

 

Return Value

 

This method does not return a value.

 

OBJRESULT

 

Returns S_OK if successful or an error value otherwise.

 

Remarks

 

The request to be sent was defined in a prior call to the Open method. The calling application can provide data to be sent to the server through the varBody parameter. If the HTTP verb of the object's Open is "GET", this method sends the request without varBody, even if it is provided by the calling application.

 
Example Code [PowerBASIC]

 

The following code example shows how to open an HTTP connection, send an HTTP request, and read the response text.

 

#INCLUDE ONCE "win32api.inc"
#INCLUDE ONCE "httprequest.inc"
 

DIM pHttpReq AS IWinHttpRequest

DIM bstrResponseText AS STRING

 

' Create an instance of the HTTP service

pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"

 

' Open an HTTP connection

pHttpReq.Open UCODE$("GET"), UCODE$("http://microsoft.com"), %FALSE

 

' Send the HTTP Request

pHttpReq.Send

 

' Get the response text

bstrResponseText = pHttpReq.ResponseText

MSGBOX ACODE$(bstrResponseText)

 

The following example shows how to post data to an HTTP server.

 

DIM pHttpReq AS IWinHttpRequest

 

' Create an instance of the HTTP service

pHttpReq = NEWCOM IWinHttpRequest "WinHttp.WinHttpRequest.5.1"

 

' Initialize an HTTP request

pHttpReq.Open UCODE$("PUT"), UCODE$("http://postserver/newdoc.htm"), %FALSE

 

' Post data to the HTTP server

pHttpReq.Send("Post Data")

 

Example Code [C++]

 

#include "stdafx.h"

#include "objbase.h"

 

#include "httprequest.h"

 

// IID for IWinHttpRequest.

const IID IID_IWinHttpRequest =

{

0x06f29373,

0x5c5a,

0x4b54,

{0xb0, 0x25, 0x6e, 0xf1, 0xbf, 0x8a, 0xbf, 0x0e}

};

 

int main(int argc, char* argv[])

{

   // variable for return value

   HRESULT    hr;

 

   // initialize COM

   hr = CoInitialize( NULL );

 

   IWinHttpRequest *  pIWinHttpRequest = NULL;

 

   BSTR            bstrResponse = NULL;

   VARIANT         varFalse;

   VARIANT         varEmpty;

 

   CLSID           clsid;

 

   VariantInit(&varFalse);

   V_VT(&varFalse)   = VT_BOOL;

   V_BOOL(&varFalse) = VARIANT_FALSE;

 

   VariantInit(&varEmpty);

   V_VT(&varEmpty) = VT_ERROR;

 

   hr = CLSIDFromProgID(L"WinHttp.WinHttpRequest.5.1", &clsid);

 

   if (SUCCEEDED(hr))

   {

       hr = CoCreateInstance(clsid, NULL,

                             CLSCTX_INPROC_SERVER,

                             IID_IWinHttpRequest,

                             (void **)&pIWinHttpRequest);

   }

   if (SUCCEEDED(hr))

   {        // Open WinHttpRequest.

           BSTR bstrMethod  = SysAllocString(L"GET");

               BSTR bstrUrl = SysAllocString(L"http://microsoft.com");

       hr = pIWinHttpRequest->Open(bstrMethod, bstrUrl, varFalse);

               SysFreeString(bstrMethod);

               SysFreeString(bstrUrl);

   }

   if (SUCCEEDED(hr))

   {        // Send Request.

       hr = pIWinHttpRequest->Send(varEmpty);

   }

   if (SUCCEEDED(hr))

   {        // Get Response text.

               hr = pIWinHttpRequest->get_ResponseText(&bstrResponse);

   }

       

       // Print response to console.

       wprintf(L"%.256s",bstrResponse);

 

       // Release memory.

   if (pIWinHttpRequest)

       pIWinHttpRequest->Release();

   if (bstrResponse)

       SysFreeString(bstrResponse);

       

       CoUninitialize();

       return 0;

}

 

Example Code [Script]

 

// Instantiate a WinHttpRequest object.

var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");

 

// Initialize an HTTP request. 

WinHttpReq.Open("GET", "http://www.microsoft.com", false);

 

// Send the HTTP request.

WinHttpReq.Send();

 

// Display the response text.

WScript.Echo(WinHttpReq.ResponseText);

 

The following example shows how to post data to an HTTP server.

 

// Instantiate a WinHttpRequest object.

var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");

 

// Initialize an HTTP request. 

WinHttpReq.Open("PUT", "http://postserver/newdoc.htm", false);

 

// Post data to the HTTP server.

WinHttpReq.Send("Post data");

 

Example Code [Visual Basic]

 

Dim HttpReq As Object

 

' Create the WinHTTPRequest ActiveX Object.

Set HttpReq = New WinHttpRequest

 

' Open an HTTP connection.

HttpReq.Open "GET", "http://microsoft.com", False

 

' Send the HTTP Request.

HttpReq.Send

 

' Get all response text.

Text1.Text = HttpReq.ResponseText

 

The following example shows how to post data to an HTTP server.

 

Dim HttpReq As Object

 

' Create the WinHTTPRequest ActiveX Object.

Set HttpReq = New WinHttpRequest

 

' Initialize an HTTP request. 

HttpReq.Open "PUT", "http://postserver/newdoc.htm", false

 

' Post data to the HTTP server.

HttpReq.Send "Post data"

 

Valid XHTML 1.0 Transitional