当我通过android应用程序调用其余的Web服务时,我得到406.Can任何人都建议我这个代码中的错误是什么以及为什么我会收到此错误?
@RequestMapping(value="/mainreservationChartPost", method = RequestMethod.POST)
public @ResponseBody ModelMap getMRChartDataPOST(@ModelAttribute ("ReservationSummaryRQDTO") ReservationSummaryRQDTO search){
ReservationSummaryDTO returnDataDTO = new ReservationSummaryDTO();
MainReservationChartWSImpl wsImpl = MRWSUtil.getInstance().getWS_ServicePort();
search.setHotelCode("BBH");
search.setReportDate(toXmlDateGMT(new Date()));
returnDataDTO = wsImpl.getReservationSummary(search);
ModelMap model = new ModelMap();
model.put("reservations", returnDataDTO);
return model;
}
Android代码
public static String POST(String url, ArrayList<NameValuePair> parameter)
throws Exception {
BufferedReader in = null;
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(url);
httpost.setHeader("Accept", "application*/*");
httpost.setHeader("Content-type",
"application/x-www-form-urlencoded");
httpost.setEntity(new UrlEncodedFormEntity(parameter, "utf-8"));
HttpResponse response = httpclient.execute(httpost);
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("hotelCode","BBH"));
//nameValuePairs.add(new BasicNameValuePair("reportDate","10-MAY-2013"));
//String response=hcc.executeHttpPost("http://10.2.241.137/ua_dat/rnd/senddata.php", nameValuePairs);
try {
String response=HttpCustomClient.POST("http://10.2.241.33/MRChartService/mainreservationChart.html", nameValuePairs);
} catch (Exception e) {
Log.d("error", e.getMessage().toString());
}
}
任何人都可以建议如何解决这个问题?此代码中的任何错误,因为我收到406错误...
答案 0 :(得分:3)
406表示请求的accept标头中请求的数据类型与服务器返回的类型不匹配。更改您接受的类型或更改您的返回哑剧类型。
答案 1 :(得分:0)
该错误是不可接受的。
字面上。
Here is some documentation on it:
这通常意味着服务以无法识别的格式将内容发回给您。它可能是错误的数据类型,或者标题可能只是搞砸了。您应该尝试使用像WireShark这样的数据包嗅探器来查看发回的内容。此外,您可能只需要指定内容类型。
如果您正在进行网络服务呼叫,并且您从未使用过数据包嗅探器,那么找出如何进行操作将是一个好主意。
答案 2 :(得分:0)