Posting XML to web server

Discussion in 'Java' started by Lee Francis Wilhelmsen, Jan 14, 2004.

  1. 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

    --
    In theory, there is no difference between theory and
    practice. But, in practice, there is.
    -- Jan L.A. van de Snepscheut
     
    Lee Francis Wilhelmsen, Jan 14, 2004
    #1
    1. Advertising

  2. Lee Francis Wilhelmsen wrote:

    >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
     
    Thomas Fritsch, Jan 14, 2004
    #2
    1. Advertising

  3. Lee Francis Wilhelmsen <> wrote:
    : 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
     
    Robert Olofsson, Jan 14, 2004
    #3
  4. "Robert Olofsson" <> wrote in message
    news:bu3ckp$m06$...
    > Lee Francis Wilhelmsen <> wrote:
    > : 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
     
    Lee Francis Wilhelmsen, Jan 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alanb
    Replies:
    2
    Views:
    575
    alanb
    Apr 23, 2004
  2. Replies:
    1
    Views:
    515
    Patrice
    Oct 20, 2005
  3. =?Utf-8?B?RGFubnk=?=
    Replies:
    1
    Views:
    1,153
    Joerg Jooss
    Dec 3, 2005
  4. AmitKu
    Replies:
    7
    Views:
    583
    John Timney \(MVP\)
    Jan 8, 2007
  5. Shawn
    Replies:
    3
    Views:
    207
    Mark Schupp
    Oct 21, 2004
Loading...

Share This Page