4 Replies Latest reply on Aug 9, 2010 7:15 AM by Hannes1234

    Send XML to Server

    Hannes1234

      Hello,

       

      I am brand new to Flex and so I have a question concerning handling XML- files. I pick up a XML- file with this MXML code:

       

      [CODE]

      <mx:HTTPService id="httpXmlDataService" url="http://localhost:8080/getData"
                          resultFormat="e4x" result="resultHandler(event)" fault="faultHandler(event)"
                          useProxy="false"
                          method="POST">  // POST has no effect
          </mx:HTTPService>

      [/CODE]

       

      At the server I use a Java- Servlet and in this Servlet always the doGet(...) method is invoked and not as I assumed the doPost(...) method (method="POST"). Does anyone know why?

       

      And the second thing is, how can I write back the XML- Data to the server? Is there also something like <mx:HTTPService ...?

       

      Thanks a lot for your help and all the best,

      Hannes

        • 1. Re: Send XML to Server
          rootsounds Level 4

          HTTPService.method = "POST" is supposed to do the trick.

           

          httpXmlDataService.contentType = "text/xml";

          httpXmlDataService.request = myXMLObject.toString();

          • 2. Re: Send XML to Server
            Hannes1234 Level 1

            >> HTTPService.method = "POST" is supposed to do the trick.

             

             

            I also thought that this is the solution but it has no effect, neither

             

            <mx:HTTPService id="httpXmlDataService" url="http://localhost:8080/getData"
                                resultFormat="e4x" result="resultHandler(event)" fault="faultHandler(event)"
                                useProxy="false"
                                method="POST">

             

             

             

             

             

             

             

            nor

             

             

            private function readXMLFile():void {
                            httpXmlDataService.method = "POST";
                            httpXmlDataService.send();
                            }

             

             

             

             

             

             

             

            Do you have any idea why this doesn't work?

             

             

             

            Could you please give a complete example of sending XML- data to the server,

            I'am a bloody beginner, so I don't know what to do with this two lines of code:

             

             

            httpXmlDataService.contentType = "text/xml";

            httpXmlDataService.request = myXMLObject.toString();

             

             

            Thanks and all the best!!!

            Best regards

            Hannes

            • 3. Re: Send XML to Server
              rootsounds Level 4

              POST would be for writing back to the server. When doing this, you set the content type and the request body. Use the GET method to fetch.

              • 4. Re: Send XML to Server
                Hannes1234 Level 1

                OK, I see, now I send my XML- data to the server like this:

                 

                private function sentXMLFile():void {
                                httpXmlDataService.method = "POST";
                                httpXmlDataService.contentType = "text/xml";
                                httpXmlDataService.request = myTree.toString();
                                httpXmlDataService.send(myTree);
                                }

                 

                But how can I get "myTree" on the server side? there is no name of "myTree" on the server- side so I can't get it like this:

                 

                protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {

                        final Object myTree = request.getParameter("myTree");
                        requestHandler(request, response);
                        }

                 

                Do you have an idea how I coul'd get "myTree" an the server- side with Java?

                 

                thanks a lot!!