0

I am trying to send a request to a server using GET that will respond with XML. I am told that I need to set the "Accept" property, code follows:

StringBuffer url = new StringBuffer(BASE_URL);
url.append(DRS_SERVICE_RELATIVE_URL);
url.append("?").append(DOC_PARAM_NAME).append("=").append(docId);
url.append("&").append(DOB_PARAM_NAME).append("=").append(dob);

try
{
    this.server = new URL(url.toString());

    URLConnection urlCon = this.server.openConnection();
    HttpURLConnection con = (HttpURLConnection)urlCon;

    con.addRequestProperty("Accept", "text/xml, application/*+xml, application/xml, text/xml, application/*+xml");

    con.connect();

    input = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String line = null;

    while((line = input.readLine()) != null)
        System.out.println(line);

I get response code 500. When I talk to the developers of the URL I am trying to access they say I am not setting the "Accept" property to XML? What am I doing wrong? How are you supposed to set that property?

EDIT: OK this is embarassing. The problem had to do with my development enviroment, specifically the way I set up a TCP/IP monitoring tool. When I stopped monitoring the network messages it worked as expected.

BigMac66
  • 1,528
  • 5
  • 19
  • 35
  • Questions: (1) Does it work if you don't include "Accept"? (2) What is the exact server error message? – gaborsch Jan 15 '13 at 18:08
  • Other than responnse 500 all it says is "Service handler performed no action; contact the server administrator." When I contact them they say the Accept is not set properly. – BigMac66 Jan 15 '13 at 19:53
  • With `WireShark` ( http://www.wireshark.org/ ) you can check what exactly goes on the TCP channel (AFAIK it also understands HTTP protocol). Filter for the server's IP address. – gaborsch Jan 15 '13 at 20:17

1 Answers1

0

The problem had to do with my development enviroment, specifically the way I set up a TCP/IP monitoring tool. When I stopped monitoring the network messages it worked as expected.

BigMac66
  • 1,528
  • 5
  • 19
  • 35