5 Replies Latest reply on Nov 13, 2006 3:11 PM by NUMB-LOCK

    HTTPService problem when sending xml

    jpwrunyan Level 1
      I found the following article on submitting XML data directly in place of value-pairs using HTTPService.
      Since I am working with Struts and all my data is XML to begin with, I thought this would be a nice clean easy way to do things:

      Sending XML Over HTTP

      Unfortunately, it doesn't seem to work... at all.

      I am sending to a "target.jsp" page that I *think* should just tell me what the document type of the request is. Since I am sending XML, it should say "XML":

      <%@ page import="java.io.BufferedReader,
      <?xml version="1.0" encoding="UTF-8" ?>
      BufferedReader br = new BufferedReader(request.getReader());
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = factory.newDocumentBuilder();
      Document doc = db.parse(new InputSource(br));
      out.print(doc.getDoctype()); //prints the original doc type as the value for <data>, right?

      Then, in my Flex application I have the following actionscript:

      var serviceCall:HTTPService = new HTTPService();
      serviceCall.method = "POST";
      serviceCall.resultFormat = mx.rpc.http.HTTPService.RESULT_FORMAT_E4X;
      serviceCall.url = "target.jsp";
      serviceCall.contentType = "application/xml";
      serviceCall.request = new XML(<blorch><a><test></test></a></blorch>);
      //not shown: listeners and display logic

      Now, the above, when executed displays its result as:

      What am I doing wrong? Why doesn't the .jsp have anything in its request??? I assume it says "null" because it doesn't have anything to begin with!
        • 1. Re: HTTPService problem when sending xml
          rkschulz Level 1
          Not sure about using JSP, but here is some code that should get you going using servlets.


          var _dataLoaderHTTPService:HTTPService;

          some method () {

          _dataLoaderHTTPService = new HTTPService();

          var params:Object = new Object();
          params.param1 =
          params.param2 =

          private function dataLoaded(e:Event):void {
          var xml:XML = new XML(_dataLoaderHTTPService.lastResult.toString());


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

          PrintWriter out = response.getWriter();
          String p1 = request.getParameter("param1");
          String p2 = request.getParameter("param2");

          out.append("<xml> ... ");


          You should be able to do the same with the JSP on the Java side.
          Hope this helps.


          • 2. Re: HTTPService problem when sending xml
            Peter Farland Level 3
            When working with HTTPServices you should use an HTTP sniffer to debug what is actually being sent on the wire... this is a more reliable test than not being sure if Java code in a JSP is working.

            Also, if you do confirm with a sniffer that nothing is being posted, instead of this:

            serviceCall.request = new XML(<blorch><a><test></test></a></blorch>);

            Can you try

            var data:XML = <blorch><a><test></test></a></blorch>;
            serviceCall.request = data;

            Or try simply:

            var data:XML = <blorch><a><test></test></a></blorch>;
            • 3. Re: HTTPService problem when sending xml
              jpwrunyan Level 1

              The code above was just one way I have tried sending XML. I have tried various other ways such as those you listed. I will, when I have a moment, go back and try again, though. In the meantime, not to be overly ignorant (or lazy), but could you perhaps tell me what an HTTP sniffer is or give a link describing how to do what you have suggested?
              • 4. Re: HTTPService problem when sending xml
                ntsiii Level 3
                I have heard a lot of folks complaining of problems with contentType= "application/xml";

                Note that rkschultx code does not use this content type.

                • 5. HTTPService problem when sending xml
                  You can also simply use the <mx:TraceTarget/> tag to spit out what is being sent and received. It even gives you the entire SOAP message. Just put <mx:TraceTarget/> as the second line of your code right under the "mx:application" line.

                  Bob I.