3 Replies Latest reply on Nov 3, 2010 1:38 AM by mlavie

    URLLoader/URLRequest not Really Using POST...

    mlavie Level 1

      I am using Flex with SDK 3.4.

       

      I am trying to make a simple POST call to an Microsoft.NET WebService which accepts only POST. The contract for the WebService is:

       

              [OperationContract]
              [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
              DataSet GetAccounts();

       

      I am trying to call it with URLLoader/URLRequest. I am sending an empty body (request=""), but I keep on getting HTTP Status 405 and in the IOErrorEvent I see that the target.data returned in the HTML screen I get when I try to access the service via a browser GET call. Could it be that a GET is being issued, despite the fact that I specified "request.method = URLRequestMethod.POST"?

       

      Has anyone else encountered this? My code follows. TIA - mlavie

       

       

       

          var loader:URLLoader = new URLLoader(); 
          var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/xml; charset=utf-8"); 
          var header2:URLRequestHeader = new URLRequestHeader("pragma", "no-cache"); 
         
          configureListeners(loader);

          var request:URLRequest = new URLRequest("http://localhost:12345/Server/WcfServicePostXml/GetAccounts"); 
         
          request.requestHeaders.push(header); 
          request.requestHeaders.push(header2); 
         
          request.method = URLRequestMethod.POST;

          request.data = ""; 
         
          trace("Sending: " + request.data);

          loader.dataFormat = URLLoaderDataFormat.TEXT; 
         
          loader.load(request); 
         } 
        
         private function configureListeners(dispatcher:IEventDispatcher):void 
         
         { 
          dispatcher.addEventListener(Event.COMPLETE, completeHandler); 
          dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
          dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); 
          dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 
         } 
        

        • 1. Re: URLLoader/URLRequest not Really Using POST...
          mlavie Level 1

          I have further proof that "request.method = URLRequestMethod.POST;" is being ignored:

           

          1) I changed the web service to GET (instead of POST), and now it works, despite the Flex client specifying " request.method = URLRequestMethod.POST;".

           

          2) I pointed the Flex client to a regular web page which does NOT allow POST, and the Flex client successfully brought the results. This page returns "405 Method not allowed" is accessed by any other client calling it by POST,

           

          Just a reminder - I'm using Flex 3.4 (I have to because I'm using the CS 5 SDK). I'd appreciate any comments from Adobe employees

           

           

          TIA,

          mlavie

          • 2. Re: URLLoader/URLRequest not Really Using POST...
            mlavie Level 1

            Correction - I am using Flex 4.0 (I deliberately moved to 4.0 to make sure 3.4 wasn't causing the problem...).

            • 3. Re: URLLoader/URLRequest not Really Using POST...
              mlavie Level 1

              SOLVED!:

               

              If "request.data" is empty ("") or null, then "request.method = URLRequestMethod.POST" is ignored, and a GET verb is issued. I do not see that documented anywhere, and in my humble opinion this is a bug. It is totally legitimate to send "request.method = URLRequestMethod.POST" with an empty body. Some webservices will have no input required and certainly a "dumb" web page containing static XML requires no input to render itself.

               

              mlavie