×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    64

    HTTP file post problem

    Hi,
    I want to post an XML file to server.I am using HTTP client example. has anybody done file post with this? how can I send file as a body? what function need to be re implemented and how? If someone can elaborate it will be great help,Thx.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: HTTP file post problem

    You might consider typing http post in the Search field of the Wiki.

  3. #3
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    64

    Re: HTTP file post problem

    I have gone through few related posts but couldn't find the exact information.

  4. #4
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    64

    Re: HTTP file post problem

    Here's my code.I'm not able to save the file on the server.I m using apache server.I have PHP script to support the upload.can someone tell me what's the problem?

    //GetNextDataPart function


    TBool CDMDatasyncPost::GetNextDataPart(TPtrC8& aDataPart)
    {
    iRetVal = EFalse;
    if ( iIsDataReleased )
    {
    if ( iPostData )
    {
    TInt offset = KMaxSubmitSize;
    if ( iStartPos + offset > iPostData->Des().Length() )
    {
    offset = iRemainingLength ;
    }
    // Copy the part buffer for posting
    TPtrC8 startRip = iPostData->Des().Mid(iStartPos);
    iPartPostBuffer.Copy((const unsigned char *)startRip.Ptr(),offset);

    aDataPart.Set(iPartPostBuffer);
    iStartPos += offset;
    iRemainingLength -= offset;
    if ( iRemainingLength == 0 )
    {
    iRetVal = ETrue;
    delete iPostData;
    iPostData= NULL;
    }
    }
    }
    else
    {
    aDataPart.Set(iPartPostBuffer);
    }
    return iRetVal;

    }

    ----------------------------------------------------------------
    //ReleaseData function

    void CDMDatasyncPost::ReleaseData()
    {
    iIsDataReleased = ETrue;
    if ( iPostDataChunk )
    {
    delete iPostDataChunk;
    iPostDataChunk = NULL;
    }
    if ( iPostData )
    {
    delete iPostData;
    iPostData = NULL;
    }
    }

    ----------------------------------------------------------------

    //Post code

    TInt CDMDatasyncPost::GetFileToPostL()
    {
    // This file is internally used hence the hardcoded file name
    _LIT( KLogName,"test.txt");
    // Changed after client comment for calling Connect() without calling Close() in the destructor

    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    TBuf<KFilePathMaxLength> filePath;
    _LIT(KPath,"c:\\data\\");
    filePath.Copy(KPath);
    filePath.Append(KLogName);
    RFile reqFile;
    TInt err = reqFile.Open(fs,filePath,EFileRead);
    User::LeaveIfError(err);
    CleanupClosePushL(reqFile);
    if ( iPostData )
    {
    delete iPostData;
    iPostData = NULL;
    }

    iPostBuffptr.Set(NULL, 0, 0);
    delete iPostDataChunk;
    iPostDataChunk = NULL;
    iPostDataChunk = HBufC8::NewMaxL(KMaxSubmitSize);
    iPostBuffptr.Set(iPostDataChunk->Des());

    User::LeaveIfError(reqFile.Read(iPostBuffptr));

    delete iPostData;
    iPostData = NULL;
    iPostData = iPostBuffptr.AllocL();
    delete iPostDataChunk;
    iPostDataChunk = NULL;

    User::LeaveIfError(reqFile.Size(iTotalsize));

    CleanupStack::PopAndDestroy(2, &fs);
    return iTotalsize;
    }

    -----------------------------------------------------------------
    //calling post

    TInt CDMHttpDataSync::IssueHttpRequestL( CDMHttpRequestData &aRequestInfo )
    {

    //Code for Switch case for post

    // Open transaction with previous method and parsed uri. This class will
    // receive transaction events in MHFRunL and MHFRunError.
    iHttpTransaction = iHttpSession.OpenTransactionL( uri, *this, method );

    if ( aRequestInfo.iMethod == EIRHttpPOST )
    {
    TInt FileSize(KErrNone);
    TRAPD(err,FileSize=iPostData->GetFileToPostL());
    if( err )
    {
    // failed to open the file to be posted hence cancel the request
    CleanupStack::PopAndDestroy(&method);
    iHttpTransaction.Close();
    return KErrCouldNotConnect;
    }
    TBuf8<KBufflengthMaxLength> bufflength;
    _LIT8(KFormat,"%d");
    bufflength.Format(KFormat,FileSize);
    aRequestInfo.iContentType.Copy(KPostContentType);
    RHTTPRequest LogRequest;
    LogRequest = iHttpTransaction.Request();
    LogRequest.SetBody((MHTTPDataSupplier&) *iPostData);
    RHTTPHeaders header = iHttpTransaction.Request().GetHeaderCollection();
    SetHeaderL(header,HTTP::EContentType,aRequestInfo.iContentType );
    SetHeaderL(header,HTTP::EContentLength,bufflength);
    }


    // Setup the headers for the HTTP request
    BuildHeadersL(aRequestInfo);

    // Submit the transaction. After this the framework will give transaction
    // events via MHFRunL and MHFRunError.
    iHttpTransaction.SubmitL();

    CleanupStack::PopAndDestroy( &method );
    iRunning = ETrue;
    return KErrNone;
    }

    -----------------------------------------------------------------
    //EGotResponseBodyData in MHFRunL

    case THTTPEvent::EGotResponseBodyData:
    {
    // Part of response's body data received. Use
    // aTransaction.Response().Body()->GetNextDataPart() to get the actual
    // body data.
    // Get the body data supplier

    MHTTPDataSupplier *body = aTransaction.Response().Body();
    TPtrC8 dataChunk;
    body->GetNextDataPart( dataChunk );
    iObserver.HttpBodyReceived( dataChunk );

    // To release the body data.
    body->ReleaseData();
    }
    break;

  5. #5
    Registered User
    Join Date
    May 2007
    Location
    Chennai
    Posts
    15

    Re: HTTP file post problem

    hi i have a .txt file in my host. In my application i want to get that .txt file and i want to write that file in my mobile device.

    How to do it?

    I can able to read the full data from that file. now i want to know how could i write that data into a file. My code is

    void CClientAppView::ClientBodyReceived(const TDesC8& aBodyData)
    {

    HBufC* tempBuf = HBufC::NewL(aBodyData.Length());
    CleanupStack::PushL(tempBuf);
    tempBuf->Des().Copy(aBodyData);

    TPtrC TempPtr=tempBuf->Des();
    CleanupStack::PopAndDestroy();
    TBuf8<128> buf8;
    //if(TempPtr.Left(10)
    TInt size = TempPtr.Size();
    TInt si = 0;
    while(si<size)
    {
    if(si<1024)
    {
    buf8.Copy(TempPtr.Mid(si,si + 127));
    WriteToFile(buf8);
    si += 128;
    }
    }


    here am try to read first 1024 data from that data. But after 128 app wil closed. Can u guide me?
    Jayaseelan.V
    Dhanus Technologies.,-INDIA.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: HTTP file post problem

    The second argument of Mid should be a constant 128 (it is length, not position).

  7. #7
    Registered User
    Join Date
    May 2007
    Location
    Chennai
    Posts
    15

    Re: HTTP file post problem

    Hi,

    Thanks for your reply. Whats my problem is, void CClientAppView::ClientBodyReceived(const TDesC8& aBodyData) in this, aBodyData's size is more than 3000..

    in my code while reading that data after 512 the application gets terminated. I don't know why it happens..

    Please give suggestion to correct my error..
    Jayaseelan.V
    Dhanus Technologies.,-INDIA.

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: HTTP file post problem

    Hmm, note that PopAndDestroy deletes the buffer for TempPtr, but you have just started using TempPtr by then.
    By the way, can it happen that you are trying to implement this method:
    Code:
    void CClientAppView::ClientBodyReceived(const TDesC8& aBodyData)
    {
    WriteToFile(aBodyData); 
    }
    ?

  9. #9
    Registered User
    Join Date
    May 2007
    Location
    Chennai
    Posts
    15

    Re: HTTP file post problem

    thanks for ur reply.

    I use this too. But in my WriteToFile methaod wad defines as

    void CClientAppView::WriteToFile(TDesC8& aContent8)
    {
    }


    If is use WriteToFile(aBodyData) means it through errors like

    function call '[CClientAppView].WriteToFile({lval} const TDesC8)' does not match
    'CClientAppView::WriteToFile(TDesC8 &)' (non-static)

    what can i do now?

    Reply soon
    Jayaseelan.V
    Dhanus Technologies.,-INDIA.

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: HTTP file post problem

    Code:
    void CClientAppView::WriteToFile(const TDesC8& aContent8)
    should help, since you cannot modify a TDesC anyway, just the compiler does not know that.

  11. #11
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    64

    Re: HTTP file post problem

    I am able to post the file.That's a great relief for me.

Similar Threads

  1. HTTP POST Problem with SDK's
    By tonyhabayeb in forum Mobile Java Tools & SDKs
    Replies: 11
    Last Post: 2006-08-10, 23:14
  2. HTTP POST Problem with SDK's
    By tonyhabayeb in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-06-16, 13:41
  3. Http post problem with emulator
    By robbin123 in forum Symbian
    Replies: 0
    Last Post: 2006-06-13, 21:37
  4. Http post problem on different phones
    By tertiusbouwer in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-05-19, 16:02
  5. J2ME HTTP Post problem
    By gilfr in forum Mobile Java General
    Replies: 2
    Last Post: 2003-06-11, 08:13

Posting Permissions

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