Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Constructing HTTP POST Url parameters

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: rathodavinash (30 Jun 2007)
Last edited: hamishwillee (03 Feb 2012)


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");
This page was last modified on 3 February 2012, at 04:05.
102 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×