Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9059579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:00:53+00:00 2026-06-16T15:00:53+00:00

I am writing an application which will send XML over HTTP to a server,

  • 0

I am writing an application which will send XML over HTTP to a server, and receive XML as the response. I am able to send XML to the server but not able to receive the response.

This is my client code:

public void sendXMLToServer(){
    System.out.println("sendXMLToServer");
    String strURL = "http://localhost:9080/MockServerMachine/sendXMLPost";
    // Get file to be posted
    String strXMLFilename = "output.xml";
    File input = new File(strXMLFilename);
    // Prepare HTTP post
    System.out.println("junaud url "+ strURL);
    PostMethod post = new PostMethod(strURL);


 // Request content will be retrieved directly
    // from the input stream
    // Per default, the request content needs to be buffered
    // in order to determine its length.
    // Request body buffering can be avoided when
    // content length is explicitly specified
    try {
        post.setRequestHeader("Content-type","application/xml");
        post.setRequestHeader("Accept","application/xml");

        post.setRequestEntity(new InputStreamRequestEntity(
                new FileInputStream(input), input.length()));
        HttpClient httpclient = new HttpClient();
        int result = httpclient.executeMethod(post);
        String xmlResponse = post.getResponseBodyAsString();
        // Display status code
        System.out.println("Response status code jun: " + result);

        // Display response
        System.out.println("Response body: ");
        System.out.println(post.getResponseBodyAsString());
        post.releaseConnection();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

This is the server side:

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

    //InputStream in = request.getInputStream();
        //URL xmlUrl = new URL(request.getRequestURL().toString());
    //InputStream in = xmlUrl.openStream();

    response.setContentLength(100);
//      PostMethod po = new PostMethod(request.getRequestURL().toString());
//      System.out.println("kikmk = "+po.getRequestEntity());

    try {
        // read this file into InputStream
        //InputStream inputStream = new FileInputStream("c:\\file.xml");
        InputStream inputStream = request.getInputStream();
        // write the inputStream to a FileOutputStream
        OutputStream out = new FileOutputStream(new File("c:\\junaidAhmedJameel.xml"));

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = inputStream.read(bytes)) != -1) {
            System.out.println(new String (bytes));
            System.out.println(read);
            out.write(bytes, 0, read);
        }

        inputStream.close();
        out.flush();
        out.close();

        System.out.println("New file created!");
        } catch (IOException e) {
        System.out.println(e.getMessage());
        }

      }

Can anyone help me out here? Any sample client/server example for sending XML over HTTP would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:00:54+00:00Added an answer on June 16, 2026 at 3:00 pm

    Ah, spotted it. Look here:

    OutputStream out = new FileOutputStream(new File("c:\\junaidAhmedJameel.xml"));
    

    That’s just going to write to the local disk. You’re not writing any content to the response stream. It’s not clear what you want to write to the response stream, but there’s a conspicuous absence of calls to response.getWriter() or response.getOutputStream().

    You’re setting the content length to 100, but not actually sending any content. Note that hard-coding the content-length is almost certainly the wrong thing to do anyway… but it’s definitely the wrong thing to do when you’re not sending any content…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm writing some kind of application that will send http requests to server. My
I am writing an iOS application which will be sent notifications over APNS from
Im writing an Server/Client Application which works with SSL(over SSLStream ), which has to
I'm writing a simple application which will connect with a server. However I want
I'm writing an application which will involve interaction with the database. The application will
I am writing a simple memory manager for my application which will free any
I am writing a new application in PHP which will be released to the
I'm writing an application which have to take a picture and send it to
I am writing a windows service which will communicate to a user level application.
I am writing a websocket test application that will have a GUI to send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.