6 Replies Latest reply on Nov 22, 2006 12:36 PM by johannki

    HTTPService POST Sending a GET Request

    johannki
      Hi--

      I am trying to make an HTTP POST request via ActionScript to a Java backend, but the HTTPService always appears to make a GET request instead of a POST even after setting the method to "POST". I've included both my .mxml code and basic java code to read the first few lines of the request.

      Any help would be appreciated.

      Thanks,
      Kip

      ------------------------------------------------------------------------------------
      .mxml:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="800" height="600"
      >
      <mx:Script>
      <![CDATA[
      import mx.rpc.http.HTTPService;

      private function submitButtonClickHandler(event:MouseEvent):void
      {
      var httpServ:HTTPService = new HTTPService();
      httpServ.url = " http://wnyc0111712.develop.ubsw.net:8069";
      httpServ.method = "POST";
      httpServ.send();
      }

      ]]>
      </mx:Script>


      <mx:Panel title="Flex HTTP" left="10" top="10" right="10" bottom="10" layout="absolute">
      <mx:Button id="submitButton" label="Submit" click="submitButtonClickHandler(event);" />
      </mx:Panel>

      </mx:Application>

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

      Java:
      public static void main(String[] args) throws Exception
      {
      ServerSocket srvSocket = new ServerSocket( 8069 );
      Socket socket = srvSocket.accept();
      BufferedInputStream inStream = new BufferedInputStream( socket.getInputStream() );

      byte[] bytes = new byte[100];
      ByteArrayOutputStream out = new ByteArrayOutputStream( inStream.available() );
      int amountRead = inStream.read( bytes );
      inStream.close();
      String inString = new String( bytes );
      System.out.println("inString: " + inString);
      }

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

      Result:
      After clicking the submit button the output is:
      "inString: GET / HTTP/1.1
      Accept: */*..."


      Versions:
      Flex verion: 2.0.1.143459
      Eclipse version: 3.2.1
      Java: 1.5.0_07