获得HTTP 406在Android的web服务呼叫 [英] Getting HTTP 406 in Android Webservice Call

查看:206
本文介绍了获得HTTP 406在Android的web服务呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到406当我调用REST Web服务通过安卓application.Can任何一个建议我什么是这个code中的错误,为什么我收到这个错误??

I'm getting 406 when i invoke the rest web service via android application.Can any one suggest me what is the error in this code and why i am getting this error ??

@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的code


Android Code

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()); 
        }




    }

任何一个可以建议如何解决这个..?在这code任何错误,因为我得到一个406错误...

Any one can suggest how to resolve this ..? any error in this code because i'm getting an 406 error ...

推荐答案

406意味着所请求的请求的接受首部数据的类型和由服务器返回的类型不匹配。要么改变你接受的类型或改变你的回报MIME类型。

406 means that the type of data being requested in the accept header of the request and the type returned by the server don't match. Either change your accepted type or change your return mime type.

这篇关于获得HTTP 406在Android的web服务呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆