Hi,
I am working with http client example.I search all the forum for posting data through http but i m not finding any answer.So i am disscussing my problem bellow
I want to crate login screen.By using username and password i hit the url which i want to send in xml format,Url respond some xml data. by taking suppose say customerId again i hit url ,server respond me some data in xml format.
I am using POST method,bellow is my code. I dont know how to send xml but i tried it.by using HTTPClient example,i does some changes.
_LIT8(KMimeType, "text/xml; charset=utf-8");
void CClientAppUi::HandleCommandL(TInt aCommand)
{
case EClientPost:
// Issue HTTP post to engine; first cancel possible existing transaction
iEngine->CancelTransaction();
iAppView->ResetL();
_LIT8(KUrl8,"http://10.10.8.3:8082/Mvts/AuthenticationUser");
_LIT(KUsername,"sagar");
_LIT(KPassword,"sagar123");
_LIT(KXmlData,"<?xml version=1.0 encoding=UTF-8?>\n"
"<USERS>\n"
"<Username>&KUsername</Username>\n"
"<Password>&KPassword</Password>\n"
"</USERS>)");
TBuf<KDefaultBufferSize> postData(KXmlData);
TBuf8<KDefaultBufferSize> postData8;
postData8.Copy(postData);
// Start transaction
TRAPD(err, iEngine->IssueHTTPPostL(KUrl8, KMimeType, postData8));
// TODO: Error handling
}
///Http client
void CClientEngine::IssueHTTPPostL(const TDesC8& aUri,
const TDesC8& aContentType,
const TDesC8& aBody)
{
// Parse string to URI
TUriParser8 uri;
uri.Parse(aUri);
// Copy data to be posted into member variable; iPostData is used later in
// methods inherited from MHTTPDataSupplier.
delete iPostData;
iPostData = 0;
iPostData = aBody.AllocL();
// Create HTTP connection
TRAPD(err, SetupConnectionL());
// User didn't select an IAP
if (err == KErrNotReady) {
HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED);
iObserver.ClientEvent(*resTxCancelled);
CleanupStack::PopAndDestroy(resTxCancelled);
return;
}
// Get request method string for HTTP POST
RStringF method = iSession.StringPool().StringF(HTTP::EPOST,
RHTTPSession::GetTable());
// Open transaction with previous method and parsed uri. This class will
// receive transaction events in MHFRunL and MHFRunError.
iTransaction = iSession.OpenTransactionL(uri, *this, method);
// Set headers for request; user agent, accepted content type and body's
// content type.
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);
SetHeaderL(hdr, HTTP::EContentType, aContentType);
// Set this class as an data supplier. Inherited MHTTPDataSupplier methods
// are called when framework needs to send body data.
MHTTPDataSupplier* dataSupplier = this;
iTransaction.Request().SetBody(*dataSupplier);
// Submit the transaction. After this the framework will give transaction
// events via MHFRunL and MHFRunError.
iTransaction.SubmitL();
iRunning = ETrue;
HBufC* resConnecting = StringLoader::LoadLC(R_HTTP_CONNECTING);
iObserver.ClientEvent(*resConnecting);
CleanupStack::PopAndDestroy(resConnecting);
}
I am not able to Post the things.
Simply i want to hit server by using username and password ,that i want to send it in xml format to server.then server will respond me xml
as for sucessfull login
<?xml version="1.0" encoding="UTF-8"?>
<LOGINRESULT>
<SUCCESS>
<MESSAGE>1</MESSAGE>
<URL>http://localhost:8080/mtracking1.2/presentation/zul/Mainpage.zul</URL>
<USERID>3d356370-df6c-102c-a6f4-000c29593aa3</USERID>
<CUSTOMERID>3d356370-df6c-102c-a6f4-000c29593aa3</CUSTOMERID>
</SUCCESS>
</LOGINRESULT>
For Invalid user:-
<LOGINRESULT>
<SUCCESS>
<MESSAGE>0</MESSAGE>
<URL>null</URL>
<USERID>null</USERID>
<CUSTOMERID>3d356370-df6c-102c-a6f4-000c29593aa3</CUSTOMERID>
</SUCCESS>
</LOGINRESULT>
then by using custmerId again i hit to server then sever respond me required XML
how to do this.
Plz help me
Thx in advance



