1 2 Previous Next 20 Replies Latest reply: Mar 17, 2010 11:01 AM by 807580 RSS

    how to post  xml over http

    750025
      Hi experts,,

      My idea is to post XMl file from client application to server.
      user.XMl file will be created then and there dynamically based on user entered data.
      For this i have a .java program in client application.
      And one important thing is My XMl file contain image in binary data,, which is in Base64Encoded format.
                        <?xml version="1.0" encoding="UTF-8"?>
                      <FileAttachment>
                                           <UserName>krish</userName>
                                           <password>rao</password>
                                          <image type="jpg">
                                                     <PictureData>
                                                      QAAAAIAGtaMS2/u6RnIAAAAIYAAAAKAAAAYm
                                                            l0bWFwLmJtcHPybWOAADMg1gBiVihm
                                                        ZJAAiwcA8RE+CIaB/6iAYj4AUEsBAhQAFAAAAAgAa1oxLb+7
                                                       pGcgAAAAhgAAAAoAAAAAAAAA
                                                        AAAgALaBAAAAAGJpdG1hcC5ibXBQSwUGAAAAAA
                                                      EAAQA4AAAASAAAAAAA
                                               </PictureData>
                                          </image>
                       </FileAttachment>
      My .xml like above.. i have to post it to server . Some thing like http://myserver:8080/Requesthandler.java which recive the xml and parse it and do some other things.

      And one thing is My server at some location and my client application at other location.
      Plz do me some help as early as possible
        • 1. Re: how to post  xml over http
          807580
          POST it the same way everything else is POSTed.
          • 2. Re: how to post  xml over http
            791266
            What's your question? What's the problem? What have you tried?
            • 3. Re: how to post  xml over http
              750025
              I think i cant give clear about question

              In general clicking on submit button in an html/Jsp file it takes the data to server.
              <html>
                       <form name=f  method=post action="provider.do">
                               <input type=text name=username>
                               <input type=password name=password>
                          
                                <input type=submit value="submit">
                      </form>
              
              </html>
              If this run the control will goes to provier.do
              it posts the Username and password to server

              Now my idea is to post An Xml file to server

              I already told my xml contain some binary data which represents image

              So i have to post This XML to server
              How do i do

              help me
              • 4. Re: how to post  xml over http
                807580
                Use a file input.
                • 5. Re: how to post  xml over http
                  750025
                  hi

                  My requirement in detail

                  If i have client, he wish to store his images in my server.
                  First i write the client application like below.
                  for that I write a jsp to Upload image and some details about client and image.
                  now i write a servlet and read all those data and prepare an XMl file using the data (alredy i wrote in first request)

                  Now I have to post this xml to another server which is ultimately stores the image
                  in server there are some programs to parse xml and do some thing.

                  Now as client application programmer i have to write some code to post the XMl to server.
                  I dont know how to post it.
                  Let me suggest
                  Plz help me
                  If i am not clear i will explain in another way
                  • 6. Re: how to post  xml over http
                    807580
                    As has already been said, just POST the XML in the body of an HTTP request. See class URL.connect() .
                    • 7. Re: how to post  xml over http
                      807580
                      Krishna_Rao_chintu wrote:
                      hi

                      My requirement in detail

                      If i have client, he wish to store his images in my server.
                      First i write the client application like below.
                      for that I write a jsp to Upload image and some details about client and image.
                      now i write a servlet and read all those data and prepare an XMl file using the data (alredy i wrote in first request)

                      Now I have to post this xml to another server which is ultimately stores the image
                      in server there are some programs to parse xml and do some thing.

                      Now as client application programmer i have to write some code to post the XMl to server.
                      I dont know how to post it.
                      Let me suggest
                      Plz help me
                      If i am not clear i will explain in another way
                      If this is from client Java code, use URL connections.

                      If this is from a web browser, use <input type="file" />.

                      Edit: Misunderstood. File input is only if you have the xml file residing on the user's computer, which you do not.

                      Edited by: ProjectMoon on Mar 17, 2010 12:17 PM
                      • 8. Re: how to post  xml over http
                        750025
                        if possible give me small code for that
                        I cant understand and Guess it.

                        Give me small Code regarding to post
                        • 9. Re: how to post  xml over http
                          807580
                          Krishna_Rao_chintu wrote:
                          if possible give me small code for that
                          I cant understand and Guess it.

                          Give me small Code regarding to post
                          Come off it! The Internet has thousands of examples of how to do this. Use a search engine.
                          • 10. Re: how to post  xml over http
                            750025
                            Thak u
                            but i am sitting in front of laptop but i cant find perfect code match to me.

                            Give me link if possible,
                            <Product>
                              <SKU>99238</SKU>
                              <Description>Super Gidgetidoo</Description>
                              <Picture>
                            Content-Description: File encoded with ENCODE64.EXE.
                            Content-Disposition: attachment; filename="foo.zip"
                            Content-Transfer-Encoding: BASE64
                            Content-Type: application/octet-stream
                            
                            UEsDBBQAAAAIAGtaMS2/u6RnIAAAAIYAAAAKAAAAYm
                            l0bWFwLmJtcHPybWOAADMg1gBiVihm
                            ZJAAiwcA8RE+CIaB/6iAYj4AUEsBAhQAFAAAAAgAa1oxLb+7
                            pGcgAAAAhgAAAAoAAAAAAAAA
                            AAAgALaBAAAAAGJpdG1hcC5ibXBQSwUGAAAAAA
                            EAAQA4AAAASAAAAAAA
                              </Picture>
                            </Product> 
                            If my xml like above and its created dynamically based on client input.

                            I find some code to post above xml, But it post an XMl file in hard disk
                            it uses output stream to post , ie read every byte in xml and write to out put stream.like below
                            response.setContentType("text/xml");
                                  response.addHeader("Content-Disposition", "attachment; filename="
                                      + fileName);
                            
                                  response.setContentLength((int) xml.length());
                                  FileInputStream input = new FileInputStream(xml);
                                  buf = new BufferedInputStream(input);
                                  int readBytes = 0;
                                  while ((readBytes = buf.read()) != -1)
                                    stream.write(readBytes);
                            But i want to post xml file as it is , means whole xml document as an element

                            let me help
                            • 11. Re: how to post  xml over http
                              807580
                              Krishna_Rao_chintu wrote:
                              Give me small Code regarding to post
                              Teh codez! Teh codez! Rapunzel, give me your codez!

                              8 posts in. Not bad going.
                              • 12. Re: how to post  xml over http
                                807580
                                Is this for a college/school/university project?
                                • 13. Re: how to post  xml over http
                                  750025
                                  Why ask like that, its assignment to me,
                                  I am new to XML and parsers,
                                  I dont know web services also
                                  i am beginer in java
                                  May be my idea and thoughts are nt follow design patterens and specifications

                                  But i want to do it as like my thoughts, by doing like that i got a chance to know all the stuff
                                  • 14. Re: how to post  xml over http
                                    807580
                                    You seem to be looking for an example that does exactly what your project requires. Life is not like that. One has to be able to read a specification and adapt and extrapolate code. I'm not going to post the code you need because I don't have exactly the code you need and even if I did you are expected to do some work to get your degree/diploma/certificate. You might get lucky but I think you would do better to spend time learning rather than just asking for code.
                                    1 2 Previous Next