×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    76

    why i am unable to get data from HTTP POST method?

    hi,
    i am using the sample from by SDK. i have tested the application with the GET method. its working fine. while for POST method. i am getting "data not found. below is my piece of code. whats the wrong with this code. plese some one help.

    void CHttpClient::StartClientL()
    {
    TBuf<256> url;
    RStringPool strP = iSess.StringPool();

    RStringF method;
    //method = strP.StringF(HTTP::EGET,RHTTPSession::GetTable()); // GET
    method = strP.StringF(HTTP::EPOST,RHTTPSession::GetTable()); // POST

    //iHasARequestBody = EFalse; // for GET
    iHasARequestBody = ETrue; // for POST

    url = _L("http://192.168.0.65/TestApp/Default.aspx");
    //url = _L("http://192.168.0.65/HeadersDisplayApp/printenv.asp");

    // Start the method off
    TBuf8<256> url8;
    url8.Copy(url);
    InvokeHttpMethodL(url8, method);
    }

    void CHttpClient::GetPostBodyManuallyL()
    {
    if (iFormEncoder)
    {
    delete iFormEncoder;
    iFormEncoder = NULL;
    }

    iFormEncoder = CHTTPFormEncoder::NewL();
    TBuf<256> name;
    TBuf<256> value;
    TBuf8<256> name8;
    TBuf8<256> value8;
    name=_L("data");
    value = _L("MyTest");
    name8.Copy(name);
    value8.Copy(value);
    iFormEncoder->AddFieldL(name8, value8);
    }

    void CHttpClient::GetRequestBodyL(RStringF& aMethod)
    {
    if (aMethod== iSess.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()))
    {
    iManualPost = ETrue;
    GetPostBodyManuallyL();
    return;
    }
    }

    void CHttpClient::InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod)
    {
    iDataChunkCount = 0;
    TUriParser8 uri;
    uri.Parse(aUri);
    iTrans = iSess.OpenTransactionL(uri, *iTransObs, aMethod);
    RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();

    // Add headers appropriate to all methods
    SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(hdr, HTTP::EAccept, KAccept);

    // Add headers and body data for methods that use request bodies
    if (iHasARequestBody)
    {
    // Content type header
    TBuf8<64> contTypeBuf;
    contTypeBuf.Copy(iReqBodyContentType);
    RStringF contTypeStr = iSess.StringPool().OpenFStringL(contTypeBuf);
    THTTPHdrVal contType(contTypeStr);
    hdr.SetFieldL(iSess.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), contType);
    contTypeStr.Close();

    GetRequestBodyL(aMethod);

    MHTTPDataSupplier* dataSupplier = this;
    dataSupplier = iFormEncoder;
    iTrans.Request().SetBody(*dataSupplier);
    }

    // submit the transaction
    iTrans.SubmitL();

    CActiveScheduler::Start();
    }

    thanks in advance.
    Thanx a lot

    With Best Regards

  2. #2
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    76

    Re: why i am unable to get data from HTTP POST method?

    i have solved my problem
    only what i have changed is content type. i.e.

    _LIT8(KContentType, "application/x-www-form-urlencoded");

    Thanks to me.
    Thanx a lot

    With Best Regards

Similar Threads

  1. Sending Huge data through GPRS (HTTP Post)
    By mockba in forum Symbian
    Replies: 4
    Last Post: 2008-05-19, 16:33
  2. Problems with HTTP POST
    By Summerman in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-11-27, 09:25
  3. http post: adding multiple fields to the data
    By claudiaresa in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2006-07-14, 17:15
  4. suckho, i have encontered the same problems. Could you tell me how you resolved it?
    By dicson_hu in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2005-12-09, 10:56
  5. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00

Posting Permissions

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