×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    19

    Angry sending HTTP POST - error 36

    Please help cause I really stuck with this thing..

    I want to send HTTP post, I have compiled symbian HTTP example for N80 (S60 3rd edition)

    I am running this function and get error -36 (disconnected).
    Can anyone say what is wrong with the code or have working example sending HTPT post request.

    HTML Code:
    void CWebClientEngine::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 = aBody.AllocL();
    
    	// 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.
    	
    
      [B]     // this is just what I have changed cause before I was getting
           // error -7334 (empty body)[/B]
    	iFormEncoder=CHTTPFormEncoder::NewL();	
    	TBuf8<100> uamipPar;
    	TBuf8<100> uamipVal;
    	uamipPar.Copy(_L8("uamip"));
    	uamipVal.Copy(_L8("192.168.182.2"));		
    	iFormEncoder->AddFieldL(uamipPar,uamipVal);
    	iTransaction.Request().SetBody(*iFormEncoder);
    	iTransaction.SubmitL();
    
    	iRunning = ETrue;
    	_LIT(KConnecting,"Connecting post...");
    	iObserver.ClientEvent(KConnecting);										
    	}
    TBool CWebClientEngine::GetNextDataPart(TPtrC8& aDataPart)
    	{
    	if(iPostData) 
    		{
    		// Provide pointer to next chunk of data (return ETrue, if last chunk)
    		// Usually only one chunk is needed, but sending big file could require
    		// loading the file in small parts.
    		aDataPart.Set(iPostData->Des());
    		}
    	return ETrue;
    	}
    I think that functions like CWebClientEngine::MHFRunL are implemented correctly because my codes are working when sending GET request.

    thanks..

  2. #2
    Regular Contributor
    Join Date
    Jun 2004
    Location
    Helsinki, Finland
    Posts
    69

    Re: sending HTTP POST - error 36

    You might want to add ContentLength header:
    ...
    SetHeaderL(hdr, HTTP::EContentLength, contentLen);
    ...

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    19

    Re: sending HTTP POST - error 36

    Quote Originally Posted by myohol
    You might want to add ContentLength header:
    ...
    SetHeaderL(hdr, HTTP::EContentLength, contentLen);
    ...
    thanks,
    but not I think that this is an Access point matter that disconnect me for whatever reason,
    With some other AP I don't set EContentLength and works correctly.

    btw this Content length is normally recommended ? How should I know it ? - if I am setting the body content in a for like this
    // specifying different parameters and its values
    iFormEncoder->AddFieldL(uamipPar,uamipVal);
    // and then submitting them to the body part..
    iTransaction.Request().SetBody(*iFormEncoder);

    So How can I what is the total lenght of the result from that Addfield function ?
    Maybe you know some trick to set body from the string like this:
    par=aaaa&button=login&user=sdgsdg etc
    instead of using form ecoder ??
    then I would also know the length of the body I have

  4. #4
    Regular Contributor
    Join Date
    Jun 2004
    Location
    Helsinki, Finland
    Posts
    69

    Re: sending HTTP POST - error 36

    Are you using emulator or the actual device? I've had experienced some strange behaviour when using the emulator. Also, does the connection open to the server you are trying to post data?

    I've not used FormEncoder, so I cannot help with that. What comes to ContentLength header take a look at W3 spec:
    ...
    14.13 Content-Length

    The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

    Content-Length = "Content-Length" ":" 1*DIGIT

    An example is

    Content-Length: 3495

    Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4.

    Any Content-Length greater than or equal to zero is a valid value. Section 4.4 describes how to determine the length of a message-body if a Content-Length is not given.

    Note that the meaning of this field is significantly different from the corresponding definition in MIME, where it is an optional field used within the "message/external-body" content-type. In HTTP, it SHOULD be sent whenever the message's length can be determined prior to being transferred, unless this is prohibited by the rules in section 4.4.
    ...

    My guess is that FormEncoder provides then length header into the request.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Re: sending HTTP POST - error 36

    I have the same problem of getting -36 error. Got it resolved my seeing your question. The client socket (accepted socket) at the server side is getting close immediately after sending the data. pls add a delay before closing the socket. It worked for me.

    -Dhinesh.

Similar Threads

  1. nokia 6600 - a problem with sending data with HTTP POST
    By Ludwik Ejsmont in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-08-31, 08:44
  2. HTTP Client - Synchronous HTTP POST Calls?
    By symbian_ravi in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2006-04-16, 11:51
  3. Error while sending HTTP Post Request
    By bhonsle in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2004-01-11, 16:28
  4. HTTP POST, sending data, any idea how to fetch in PHP?
    By imarenic in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2003-11-13, 21:05
  5. Problems with sending http post from 7650
    By dotomaz in forum Mobile Java General
    Replies: 2
    Last Post: 2002-12-23, 09:49

Posting Permissions

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