• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending XML on a URLConnection to a daemon  RSS feed

 
Paid O'Cuana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm having problems sending an xml document to a Java daemon, using a URLConnection. Now, the XML arrives at the daemon, the connection works and everything's fine there - but the daemon expects only XML, ot headers tha seem to be sent too. Therefore, the daemon sees bad xml and I'm getting the following response:

Does anyone know how I can remove the headers and send only the XML. Should I use something other than a URLConnection class?
Here's where I do the work. The URLConncetion is called, brilliantly, 'connection':

Here's what the daemon receives:
17:53:35 11/02/2003 <C0> API XML command:
POST / HTTP/1.1User-Agent: Java/1.4.2_02Host: 127.0.0.1:3619Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2Connection: keep-aliveContent-Type: application/x-www-form-urlencodedContent-Length: 121<?xml version="1.0" ?><wapi clTRID="luciditytechnologies.0312020001"><check><domain name="example.us" /></check></wapi> [FINEST]
[ December 02, 2003: Message edited by: Paid O'Cuana ]
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use java.net.URLConnection. That's abstract. If you are using HttpURLConnection it would only make sense that it would prepend HTTP headers to whatever request you make. What protocol does your daemon expect you to use? Just an XML message? Open a plain java.net.Socket and send the text.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're stuck with URL & HTTP instead of raw sockets, the receiving end will have to be coded to discard the headers. It's really easy - just readln() and discard the line until you get a zero-length string. Then the XML follows.
 
Paid O'Cuana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, the sockets option is best for me. I can't alter the receiving end, so the changes have to be at my end.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!