当我通过android应用程序调用rest web服务时,我得到了406。有人能告诉我这段代码中的错误是什么以及为什么我得到这个错误吗?是吗?
rest web服务

@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错误…

最佳答案

406表示请求的接受头中请求的数据类型与服务器返回的类型不匹配。更改接受的类型或更改返回的mime类型。

关于java - 在Android Webservice调用中获取HTTP 406,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16536171/

10-09 06:59