tags:

views:

32

answers:

1

Maybe someone here can help me...

I wrote a very simple java http client, which sends an xml as post data to a webserver. Now strangely our customer reports that in the postdata there is a trailing ampersand. I have absolutely no clue how that can be if you look at the source code, where I removed every variable...

public static void main(String[] args) {
    try {
    final URL httpURL = new URL(args[0]);

    String request = "<root/>";

    HttpURLConnection connection = (HttpURLConnection)httpURL.openConnection();
    connection.setRequestMethod("POST");
    connection.setDoOutput(true);

    OutputStream os = connection.getOutputStream();
    os.write(request.getBytes());
    os.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String tmp;
    String xml = new String();
    while ((tmp = in.readLine()) != null) {
        xml = xml.concat(tmp);
    }
    connection.getInputStream().close();
    connection.disconnect();
    System.out.println("Result: " + xml);
    } catch (Exception e) {
        System.err.println("Exception ocurred " + e);
    }
}

As you can see, currenlty we are sending a fixed "xml" which is only a tag.

Does anyone know if there is a know bug or a scenario, where something like that can happen?

I appreciate every help :). Thanks!

+1  A: 

I cannot seen any problem in your code that would cause an ampersand to be sent to the server. I suspect that the problem may be on the server side.

Try using wireshark or something like that to capture the TCP packets that get sent to the server and see if you can see the stray character there.

Stephen C