当我通过 android 应用程序调用其余 Web 服务时,我得到 406。任何人都可以建议我此代码中的错误是什么以及为什么我会收到此错误?
休息网络服务
@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;
}
安卓代码
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 错误...