Constructing HTTP POST Url parameters(From Forum Nokia Wiki)

 

This article shows how to send parameters along with the URL in an HTTP POST.

Consider that a web server needs some parameters for e.g.

// URL for POST request.
_LIT8(KPostUri, "http://mysite.net/test/update");

The following parameters need to be posted to the above URL, username/password

_LIT8(KPostParamName1, "username");
_LIT8(KPostParamName2, "password");

This can be done using the HTTP Client with form encoder using class CHTTPFormEncoder

//Construction
iFormEncoder = CHTTPFormEncoder::NewL();

In the POST request:

void CHTTPExampleEngine::PostRequestL(const TDesC& aUsername,const TDesC& aPassword)
{
TBuf8<50> iTemp;
TBuf8<50> iTemp2;
 
iTemp.Copy(aUsername);
iTemp2.Copy(KPostParamName1);
iFormEncoder->AddFieldL(iTemp2,iTemp);
 
iTemp.Copy(aPassword);
iTemp2.Copy(KPostParamName2);
iFormEncoder->AddFieldL(iTemp2,iTemp);
 
....
....
 
iTransaction.Request().SetBody(*iFormEncoder);
iTransaction.SubmitL();
}

Remember the following:

_LIT8(KUserAgent, "HTTPExample (1.0)");	// Name of this client app
_LIT8(KAccept, "text/*");// Accept any (but only) text content
_LIT8(KPostParamName1, "username");//Name of the parameter in a POST request
_LIT8(KPostParamName2, "password");
_LIT8(KPostContentType, "text/*");//Content type sent in a POST request
_LIT8(KContentTypeForm, "application/x-www-form-urlencoded/0");

你可能感兴趣的:(Web,server,url,Class,Parameters,Nokia)