×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    47

    Sending POST data

    Hi,

    I have been trying to use XMLHttpRequest to send POST data from a widget.

    Here is my code:

    Code:
    var pdata = "POSTDATATOSEND";
    reqp = new XMLHttpRequest();
    reqp.onreadystatechange = postCallback;
    reqp.open("POST", url, true);
    reqV.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    reqp.setRequestHeader("Content-length", pdata.length);
    reqp.setRequestHeader("Connection", "close");
    reqp.send(pdata);
    And then the call back function
    Code:
    function postCallback()
    {
    	//alert (reqV.readyState);
      	if (reqV.readyState == 4)
      	{
        	if (reqV.status == 200)
        	{
          		/*
           		* little overhead here, one could use also string for version info
           		*/
          		alert (reqp.responseText);
        	}
        	else
        	{
          		alert( "connection error: " + reqp.status );
        	}
      	}
    }
    I keep getting null in the alert box that outputs reqp.responseText

    Is POST method not allowed supported in Widgets? Going through the examples I only see GET used.

    regards,
    Magnus

  2. #2
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Germany
    Posts
    54

    Thumbs down Re: Sending POST data

    Hello,

    thank you for submitting this issue. The S60 browser also does not support XHR with HTTP post. Nokia is aware of this issue.

    Update:

    Cf.: http://discussion.forum.nokia.com/fo...2&postcount=75
    Cf.: http://discussion.forum.nokia.com/fo...d.php?t=102000
    Cf.: http://blogs.forum.nokia.com/blog/ha...-some-comments
    Last edited by phg04; 2008-04-17 at 06:41.

  3. #3
    Regular Contributor
    Join Date
    Dec 2007
    Posts
    60

    Re: Sending POST data

    Quote Originally Posted by phg04 View Post
    Hello,
    thank you for submitting this issue. The S60 browser also does not support XHR with HTTP post. Nokia is aware of this issue.
    I'm not able to confirm this right now, but I recall having issues with XHR POST in the emulator but having it working correctly in actual devices. In contrast to your code, however, I have never specified HTTP headers for content length or encoding myself.

    Peppe

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    47

    Re: Sending POST data

    Hi,

    Thanks for the reply, I usually also never set the Content length header my self just threw it in to be sure (I think it is usually set by the object it self before sending the request).

    I have also verified on the server side that I don't get any data in raw post data.

    Haven't tried on the device it self though.

    I think it is very strange if only GET method is supported and very limiting. It is not possible to talk to for example SOAP services through GET and talking to RESTful services needs the whole array of HTTP methods (GET, POST, PUT, DELETE) to be supported for proper implementation. I haven't tried the other methods though.

    regards,
    Magnus

  5. #5
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Germany
    Posts
    54

    Thumbs down Re: Sending POST data

    Hello,

    it is true that Http post does not work on the emulator but on the real device and RDA.

    But if I try to send additional XHR Http headers with RDA they are not not sent (N95 and N96 Protoype) and that's bad because Ajax often uses additional headers with Http post.

  6. #6
    Registered User
    Join Date
    May 2008
    Location
    California
    Posts
    13

    Re: Sending POST data

    I just came across this problem today. If at all possible try using https instead of http. That seems to work even on the emulator.

    I can also confirm that Ajax POST request using http URLs do work on target even though they don't work on the emulator.

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Re: Sending POST data

    Hi,

    I have tried uploading files on my widget using nokia's wrt on a 5800 phone but the application crashes down upon upload. I'm uploading using form with post method together with some fields necessary for the post but never reaches the server side.

    <form target="upload_target" id="postForm" name="postForm" method="post" onsubmit="postHandler();" enctype="multipart/form-data" action="http://www.mywidgetserverside.com">
    <input type="hidden" name="method" value="postMessageWithBinary"/>
    <input type="file" name="file" id="filefield" onchange="setFilename();"/>
    <input type="hidden" name="filename" id="filename" value=""/>
    <input type="hidden" name="user_id" value=\''+userId+'\'/>
    <input type="hidden" name="session_id" value=\''+sessionId+'\'/>
    <input type="hidden" name="client_id" value=\''+clientId+'\'/>
    <input type="hidden" name="message" id="message" value="msg"/>
    <div><input type="submit" id="submitpost" name="submit" value="Post"/></div>
    </form>
    Last edited by zbarot; 2009-09-04 at 07:43.

  8. #8
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Sending POST data

    Hi zbarot,

    have you checked if the postHandler() function correctly executes?

    On which device(s) are you experiencing this issue?

    Pit

  9. #9
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Re: Sending POST data

    Hi jappit,

    Thanks for the reply. I modified the posthandler function and it's now working.

Similar Threads

  1. J2ME encrypt C# decrypt
    By josual in forum Mobile Java Networking & Messaging & Security
    Replies: 13
    Last Post: 2008-10-20, 04:29
  2. sending HTTP POST - error 36
    By tomasz.florczak in forum Symbian
    Replies: 4
    Last Post: 2008-03-21, 20:22
  3. Replies: 4
    Last Post: 2006-12-07, 13:45
  4. how to use udp, for sending data server to client
    By acayir in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-08-02, 19:18
  5. 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

Posting Permissions

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