[英]Java set accept on http get
I am trying to send a request to a server using GET that will respond with XML. 我正在尝试使用GET将请求发送到服务器,该请求将以XML响应。 I am told that I need to set the "Accept" property, code follows: 有人告诉我需要设置“ Accept”属性,代码如下:
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? 我得到响应代码500。当我与URL的开发人员交谈时,我试图访问他们,他们说我没有将XML的“ Accept”属性设置为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. 问题与我的开发环境有关,特别是与我设置TCP / IP监视工具的方式有关。 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. 问题与我的开发环境有关,特别是与我设置TCP / IP监视工具的方式有关。 When I stopped monitoring the network messages it worked as expected. 当我停止监视网络消息时,它按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.