Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 11th, 2005, 10:46 AM
Friend of Wrox
Join Date: Nov 2003
Location: Johannesburg, , South Africa.
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default XML HTTP Post


I am new to using xml with HTTP posting and would like some advice. I need to read an xml file and post the xml data via http to a webserver.

The problem is the webserver returns that no data has been sent. What I have got is as follows:

1. A text file containing the xml data. I read from the text file as follows:

FileInputStream fis = new FileInputStream("c:/test.txt");
        int x= fis.available();
        byte b[]= new byte[x];
        String xmldata = new String(b);

2. The I do the HTTP post as follows

String hostname = "wsisf29";
      int port = 7001;
      InetAddress addr = InetAddress.getByName(hostname);
      Socket sock = new Socket(addr, port);
      //Send header
      String path = "/aws/core/online";
      BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"UTF-8"));

      System.out.println("Start Writing");
     wr.write("POST " + path + " HTTP/1.0\r\n");
     wr.write("Host: www.pascalbotte.be\r\n");
      wr.write("Content-Length: " + xmldata.length() + "\r\n");
      wr.write("Content-Type: text/xml; charset=\"utf-8\"\r\n");
               // System.out.println(xmldata.);
      //Send data


If I do a sout on xml data it does return the whole set of xml text. However the server returns data sent invalid. Do i need to post the xml data line by line?

Any advice appreciated.

Reply With Quote
  #2 (permalink)  
Old May 21st, 2005, 03:40 AM
Registered User
Join Date: May 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts


If not already done, change the Host in your mime header.

Hope this help,

Reply With Quote
  #3 (permalink)  
Old June 2nd, 2005, 10:59 AM
Registered User
Join Date: Jun 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

I have done sth similar.
Maybe it will help.
String data = "HERE IS XML FILE";
String path = "/servlet/xml";
osw.write("POST "+path+" HTTP/1.0\r\n");
osw.write("Content-Length: "+data.length()+"\r\n");
osw.write("Content-Type: application/x-www-form-urlencoded\r\n");
osw.write("Connection: keep-alive\r\n");
And it works fine.
BTW. for sure you dont need to POST xml file line by line.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP post silver_scar C# 2005 0 July 31st, 2006 09:52 AM
HTTP POST/GET d_alchemist JSP Basics 1 April 24th, 2006 09:18 AM
Sending XML via http post, using servlet kermitus Servlets 1 March 14th, 2006 07:03 PM
HTTP-POST with C# jcascio ASP.NET 1.0 and 1.1 Professional 3 April 12th, 2004 01:15 PM
Single HTTP POST - Multiple XML docs denniswong288 XML 1 August 26th, 2003 05:05 AM

All times are GMT -4. The time now is 02:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.