Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2782] HTTPClient will not send a POST HTTP request

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2011-08-10T02:19:34.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterKeith Miller
AssigneeTony Guntharp
Created2011-07-24T20:32:58.000+0000
Updated2016-03-08T07:47:41.000+0000

Description

All requests coming to the server from HTTPClient are GET requests, no matter what I set it to. Here is the code:
var request = Titanium.Network.createHTTPClient();
request.open('POST', "http://test.com");
request.onload = function() {
    try {
        var content = JSON.parse(this.responseText);
        if(content.error == undefined) {
            // do some things
        } else {
            alert(content.error);
        }
    } catch (err) {
        Titanium.API.error(err);
        Titanium.UI.createAlertDialog({
            message : err,
            title : "Remote Server Error"
        });
    }
};
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send({ test: 'test'});
I've also tried not setting the header and also passing in the data as a string instead of an object.

Attachments

FileDateSize
android.log2011-07-25T08:17:14.000+00004246
app.js2011-07-25T08:17:14.000+0000765
iphone.txt2011-07-25T08:17:14.000+00001820

Comments

  1. Paul Dowsett 2011-07-25

    Keith The information listed in the environment section seems to imply that you have observed this issue for both mobile AND desktop apps. As I'm able to successfully send POST requests for my own mobile projects, I'd be surprised if that is the case. Please explicitly state whether this relates to iPhone or Android. You need to provide a proper [usecase](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-CreatingGoodUsecases), which is concise code that demonstrates the issue and runs without modification when pasted into an app.js file. You also should consult the community via a Q&A question before raising a ticket. Please provide the link to that question. Please read the [Jira Ticket Checklist](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-Summary%3AJiraTicketChecklist) to help you correct this ticket, and before raising any more. Thanks
  2. Paul Dowsett 2011-07-25

    Also, please provide the log of the failed request. Thanks
  3. Keith Miller 2011-07-25

    Sorry about that. I marked the component as Mobile, since I'm only using Titanium Studio for mobile development. It is happening in both the iPhone and Android, emulators and the actual phones. I also cleaned the project's build directory. I have attached both the app.js and the log files for when this happens. Here is the Q&A link: http://developer.appcelerator.com/question/123135/httpclient-will-not-send-a-post-http-request#comment-91925 This code seems to work fine for other people, so it seems like a weird bug that it's not working for me. How can I see the actual request the code is sending? Thanks.
  4. Keith Miller 2011-07-25

    So, the following code works:
       var request = Titanium.Network.createHTTPClient();
       
       request.onerror = function(e)
       {
           Ti.UI.createAlertDialog({title:'Error', message:e.error}).show();
           Ti.API.info('IN ERROR ' + e.error);
       };
       request.setTimeout(20000);
       request.onload = function(e)
       {
           var content = JSON.parse(this.responseText);
           Titanium.API.info(content);
           if(content.error == undefined) {
               // do some things
               alert('worked');
           } else {
               alert(content.error);
           }
       };
       request.onsendstream = function(e)
       {
           //ind.value = e.progress ;
           Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress);
       };
       request.open('POST','http://www.israelnetdaily.com/json.php');
       
       request.send({test:'test',purpose:'newaccount'});
       
    So weird. At least it's working now.
  5. Paul Dowsett 2011-08-10

    Great work, Keith, glad you fixed it. You can inspect the network traffic using a protocol analyzer, such as [Wireshark](http://www.wireshark.org/). Cheers
  6. Paul Dowsett 2011-08-10

    User confirmed problem was with code.
  7. Paul Dowsett 2011-10-07

    Closing due to inactivity.

JSON Source