8 Replies Latest reply on Oct 18, 2007 8:32 AM by ntsiii

    posting XML to REST interface

    djbagley Level 1

      I have a rest interface that excepts posts of Content-type multipart/form-data, this interface digests the XML that is posted and returns a xml response.
      I'm trying to get my flex client to comunicate with it using the following code:

      categoryRequest.url = " http://localhost:8080/sdmxRegistry3/restInterface";
      categoryRequest.method = "post";
      categoryRequest.request = xmlQuery.toString;
      <mx:HTTPService id="categoryRequest" resultFormat="e4x" useProxy="false" ></mx:HTTPService>

      The problem is returns the follwoing error.

      Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost:8080/sdmxRegistry3/restInterface" URL: http://localhost:8080/sdmxRegistry3/restInterface

      I'm new to Flex so I'm still feeling my way, but if I can overcome this problem it would be really help me out.

      Hope someone can help..


        • 1. Re: posting XML to REST interface
          ntsiii Level 3
          The Flex code looks ok, except when working with XML, ALWAYS use toXMLString(), never toString()... that may be your main error, toString is a method, not a property, but still, always use toXMLString().

          Try that fix first.
          • 2. Re: posting XML to REST interface
            ntsiii Level 3
            For future reference, flex currently only supports the methods, GET and POST, and not the other REST methods.
            • 3. Re: posting XML to REST interface
              djbagley Level 1
              Thanks for the quick response.

              I've made the code changes, (my typo on the method / property mix up.)

              But it still returns the same error, the weird thing is that it doesn't seem to hit the rest service. I've got it running in debug on the server side and I don't see any activity.

              is there any debug infomation I can look at as the error is not very clear.


              • 4. Re: posting XML to REST interface
                djbagley Level 1
                Interestingly enough it looks like the Flex client doesn’t ever call the POST service, I’ve just put in a GET handler in the server and it’s this service it tries to use. I’ve modified my flex code to this:

                dataflowRequest.url = " http://localhost:8080/sdmxRegistry3/restInterface";
                dataflowRequest.method = "post";
                dataFlowQuery.QueryStructureRequest.registry::DataflowRef.registry::URN = URN;
                dataflowRequest.request = dataFlowQuery.toXMLString();

                I've also changed the mxml to have a POST attribute but it still uses the GET

                <mx:HTTPService id="dataflowRequest" resultFormat="e4x" useProxy="false" method="POST" ></mx:HTTPService>

                Strange I'm at a loss to know why the post service isn't being called.

                Any feedback would be great.



                • 5. Re: posting XML to REST interface
                  djbagley Level 1

                  So it looks like you need to set a contentType for it send the post request.

                  • 6. Re: posting XML to REST interface
                    ntsiii Level 3
                    No, that is not necessary.

                    But if the post body is empty, Flex automatically uses GET. Could that be your issue? Could dataFlowQuery be empty? Hard code something to test it.

                    • 7. Re: posting XML to REST interface
                      djbagley Level 1
                      Hmm ok,

                      well I'm 99% sure it is happening in my case, take the contentType off goes uses GET service, add it and it uses POST no other changes.

                      For what reasons I don’t know but I’m as sure as I can be that this is happening in my case.

                      I’ve now got it working by adding a handler into the POST service on the server for contentType application/text, if I use application/xml from Flex it escapes all my tags and I need it to go through as straight text. Seems to work ok.
                      • 8. Re: posting XML to REST interface
                        ntsiii Level 3
                        Yes, setting contentType can cause some problems. I leave it the default, which is the normal multipart/form-data, and POST xml strings as the value side of a name=value pair.

                        But if you have it working and are comfortable, then that is fine.