Posting XML to web server

  • Thread starter Lee Francis Wilhelmsen
  • Start date
L

Lee Francis Wilhelmsen

Hi

Not sure this is totally on topic, but I imagine someone here can answer
this. (Is there a better group?)

I'm trying to post some XML data to a web server using a HTTPS connection.
I'm using java to do this.
Does this look right as a valid HTTP request to send? It seems the server
can't understand the xml part.

POST /servlet HTTP/1.1
Host: serverhostname
Authorization: Basic JSK4RL5JW3ER

<?xml version="1.0"?>
<request>
<requestcontents/>
</request>

Must I add a Content-Length header? I have tried that as well, but I'm not
100% sure I calcualted the correct content length. I used

int length = new String("xml content as string").getBytes().length;

Must the XML be URL encoded? If so, do you then have to calculate the length
of the encoded xml instead of the original xml?

Forgive my ignorance.

regards
Lee Francis
 
T

Thomas Fritsch

Lee said:
Hi

Not sure this is totally on topic, but I imagine someone here can answer
this. (Is there a better group?)

I'm trying to post some XML data to a web server using a HTTPS connection.
I'm using java to do this.
Does this look right as a valid HTTP request to send? It seems the server
can't understand the xml part.

POST /servlet HTTP/1.1
Host: serverhostname
Authorization: Basic JSK4RL5JW3ER

<?xml version="1.0"?>
<request>
<requestcontents/>
</request>

Must I add a Content-Length header?
Yes, Content-Length is required in POST.
See RFC 1945 (the HTTP/1.0 specification)
http://www.rfc-editor.org/cgi-bin/rfcdoctype.pl?loc=RFC&letsgo=1945&type=ftp&file_format=txt
especially in chapter "8.3 POST".
I have tried that as well, but I'm not
100% sure I calcualted the correct content length. I used

int length = new String("xml content as string").getBytes().length;

Must the XML be URL encoded? If so, do you then have to calculate the length
of the encoded xml instead of the original xml?

Forgive my ignorance.

regards
Lee Francis
Regards
Thomas
______________________________________________________
Thomas <dot> Fritsch <at> ops <dot> de
 
R

Robert Olofsson

: Not sure this is totally on topic, but I imagine someone here can answer
: this. (Is there a better group?)

Probably, this is not a java question...

: I'm trying to post some XML data to a web server using a HTTPS connection.
: I'm using java to do this.

If its encrypted or not should not matter...

: Does this look right as a valid HTTP request to send? It seems the server
: can't understand the xml part.

: POST /servlet HTTP/1.1
: Host: serverhostname
: Authorization: Basic JSK4RL5JW3ER

: <?xml version="1.0"?>
: <request>
: <requestcontents/>
: </request>


You do not have a Content-Length. You could use chunked transport
instead if you want to, but then you need other headers.
Go read rfc 2616 for more information on HTTP/1.1.

Your authorization header seems broken. the data should be the
<username>:<password> and then base 64 coded.
decoding your token gives: '%"?D?I[qp' (may have cut and paste errors
for strange charachters here) and I do not see any ':' in there.
Go read rfc 2617 for basic authentication.

: Must the XML be URL encoded? If so, do you then have to calculate the length
: of the encoded xml instead of the original xml?

Depends on how your server wants to read the data...
Normally when you post a form you get data in the format:
data=some%20text&data2=some%20more%20text
(which can be read like data = some text, data2 = some more text). It
is up to the reciever to parse the data so how you send depends upon
how you write the servlet/cgi/asp...

/robo
 
L

Lee Francis Wilhelmsen

Robert Olofsson said:
: Not sure this is totally on topic, but I imagine someone here can answer
: this. (Is there a better group?)

Probably, this is not a java question...

Do you know of any? Are there any for discussing the contents of certain
RFC's / Protocols?
: Does this look right as a valid HTTP request to send? It seems the server
: can't understand the xml part.

: POST /servlet HTTP/1.1
: Host: serverhostname
: Authorization: Basic JSK4RL5JW3ER

: <?xml version="1.0"?>
: <request>
: <requestcontents/>
: </request>


You do not have a Content-Length. You could use chunked transport
instead if you want to, but then you need other headers.
Go read rfc 2616 for more information on HTTP/1.1.

Yes... but if the String s is to be sent would it correct to calculate the
length by doing something like this:

s.getBytes().length
or
URLEncoder.encode(s).getBytes().length

to get the content length? That's what I've been using and it still won't
work.

Regarding RFC2616, RFC1945 and RFC2617 - I have read through them, but not
studied them. So I guess you could say that I've just flipped through them.
:)
They are rather *heavy* and I haven't been given the time or resources to
read them from start to finnish.
Your authorization header seems broken. the data should be the
<username>:<password> and then base 64 coded.
decoding your token gives: '%"?D?I[qp' (may have cut and paste errors
for strange charachters here) and I do not see any ':' in there.

I just wrote something there, not the actual base64 encoded string. I wasn't
expecting someone to base64 decode it :)
: Must the XML be URL encoded? If so, do you then have to calculate the length
: of the encoded xml instead of the original xml?

Depends on how your server wants to read the data...
Normally when you post a form you get data in the format:
data=some%20text&data2=some%20more%20text
(which can be read like data = some text, data2 = some more text). It
is up to the reciever to parse the data so how you send depends upon
how you write the servlet/cgi/asp...

But if you Url encode the content, do you have to set any specific HTTP
headers or is this just down the the receiving program?

Regards
Lee Francis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top