Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 06:53, 25 September 2007.

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");
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX