1 Reply Latest reply on Feb 20, 2009 7:43 PM by Newsgroup_User

    How to make POST request with HTTPService?

    garry.b
      Hi,

      When using AS3 to generate an HTTP POST request:

      var service:HTTPService = new HTTPService ();
      service.url = " http://localhost:9090/service";
      service.method = "post";
      // service.request = {itemId: "12345"};
      service.send ({itemId: "12345"});

      my CherryPy web server complains about unexpected body parameters:

      HTTPError: (400, 'Unexpected body parameters: itemId')

      Using Firebug's Network display, its Post tab shows the following content:

      Referer: http://localhost:8080/log/log-1.0-SNAPSHOT.swf
      Content-type: application/x-www-form-urlencoded
      Content-length: 12

      itemId=12345

      which looks very strange to me as I would expect the Referer, etc., request headers to show up in the Request Headers section and not as POST body content. While this could be some Firebug issue, I think the request message is really formatted incorrectly. When the web server gets the request, it does recognize 'itemId' as a body parameter but then complains that it's unexpected.

      I've googled the error message, studied HTTPService examples, spent several
      hours playing with it and am stumped. Tracy Spratt suggested setting the service 'request' to force a POST and I tried it but am getting the same error. How do I make a POST request? Can I get POST data into the message body? Stick with URL parameters only?

      Thanks, Garry
        • 1. Re: How to make POST request with HTTPService?
          Level 7

          "garry.b" <webforumsuser@macromedia.com> wrote in message
          news:gnndbf$i2q$1@forums.macromedia.com...
          > Hi,
          >
          > When using AS3 to generate an HTTP POST request:
          >
          > var service:HTTPService = new HTTPService ();
          > service.url = " http://localhost:9090/service";
          > service.method = "post";
          > // service.request = {itemId: "12345"};
          > service.send ({itemId: "12345"});
          >
          > my CherryPy web server complains about unexpected body parameters:
          >
          > HTTPError: (400, 'Unexpected body parameters: itemId')
          >
          > Using Firebug's Network display, its Post tab shows the following content:
          >
          > Referer: http://localhost:8080/log/log-1.0-SNAPSHOT.swf
          > Content-type: application/x-www-form-urlencoded
          > Content-length: 12
          >
          > itemId=12345
          >
          > which looks very strange to me as I would expect the Referer, etc.,
          > request
          > headers to show up in the Request Headers section and not as POST body
          > content.
          > While this could be some Firebug issue, I think the request message is
          > really
          > formatted incorrectly. When the web server gets the request, it does
          > recognize
          > 'itemId' as a body parameter but then complains that it's unexpected.
          >
          > I've googled the error message, studied HTTPService examples, spent
          > several
          > hours playing with it and am stumped. Tracy Spratt suggested setting the
          > service 'request' to force a POST and I tried it but am getting the same
          > error.
          > How do I make a POST request? Can I get POST data into the message body?
          > Stick with URL parameters only?

          What happens if you post to the same service using an html form?