×

Discussion Board

Results 1 to 4 of 4

Thread: HTTP Problem

  1. #1
    Regular Contributor
    Join Date
    Jun 2007
    Posts
    51

    HTTP Problem

    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

  2. #2
    Registered User
    Join Date
    Oct 2009
    Posts
    7

    Re: HTTP Problem

    Im also suffering form this matter, I want to post some xml data to google calendar server which should send as "application/Atom+xml" MIME type. I tried for weeks. Bud didn't come up with a solution, Server says the thransaction is OK and send 200 status code, But POST XML data didnt fetch from the server.
    please help me

    Regards
    Enriko

  3. #3
    Regular Contributor
    Join Date
    Jun 2007
    Posts
    51

    Re: HTTP Problem

    Anybody please give response. give any solution

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    42

    Re: HTTP Problem

    hi,
    When u request for the server using post method did you get any response back in MHFRunL() funtion of THTTPEvent::EGotResponseBodyData case?

    i has also done the same thing.when i got the response in mhfrunl funtion i write all data in a file and used xml parser.


    Regards,
    ketan

Similar Threads

  1. Nokia N70 - HTTP POST problem
    By heuven in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-04-13, 15:48
  2. access points problem with HTTP client api
    By Svat_ in forum Symbian
    Replies: 1
    Last Post: 2006-12-26, 16:19
  3. Problem with HTTP POST
    By thathoo in forum Mobile Java General
    Replies: 2
    Last Post: 2006-12-18, 18:23
  4. Problem in Http Connection
    By jaceline in forum Mobile Java General
    Replies: 0
    Last Post: 2005-10-14, 04:08
  5. Replies: 2
    Last Post: 2003-02-19, 03:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×