문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top