如何在android Asynctask中修复414(Request-URI Too Long)错误?

时间:2015-07-01 07:21:43

标签: android sql-server wcf-rest

使用wcf rest服务我使用asynctask httpget从我的android应用程序将数据发布到SQL服务器,但它正在抛出414 error。最大URL长度是2097151,但我的URL长度是20097。 这是抛出错误的代码:

String url="http://192.168.1.6:44123/MobileServices.svc/GetAllReportsMethod?";
        //String url="http://192.168.1.200:51123/MobileServices.svc/GetAllReportsMethod?";
        //String url="http://192.168.1.21:55123/MobileServices.svc/GetAllReportsMethod?";
        String parameters="spName="+URLEncoder.encode(spname)+"&inputxele="+URLEncoder.encode(inputxele)+"&transType="+URLEncoder.encode(transtype);
        InputStream instream =null;
        String ur=url+parameters;
        String count=String.valueOf(ur.length());
        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet get=null;
            try
            {
                get=new HttpGet(ur);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            HttpResponse response=null;
            try
            {
                response = httpclient.execute(get);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            StatusLine statusLine = response.getStatusLine();
            BufferedReader bufferreader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String msg="";
            String line = ""; 
            while ((line = bufferreader.readLine()) != null)
            {
                msg += line;
            }
            Log.i("msg=",""+msg);
            if(statusLine.getStatusCode() == HttpStatus.SC_OK)
            {
                result="success";
            }
        }

0 个答案:

没有答案