HttpResponse apache在使用ArcbicURL的android中无法正常工作

时间:2015-05-19 09:16:25

标签: android apache httpclient urlconnection

我有以下代码。

当我发送包含arabic参数的URL时,它使用apache库失败。 使用相同的URL,它可以正常使用Java URLConnection。

我的网址 http://10.0.183.100:8080/arcgis/rest/services/NJMPROD/GazAdmin_Ar/MapServer/0/query&where=Upper%28NJMPROD3.LandMarkP.ARNAME%29+like+%27%25+%D8%AD%D9%85%D8%AF%25%27。 我试过URLEncoder.encode()而没有相同的

public class HttpAsyncTask extends AsyncTask<String, Void, String> {
   boolean tryIt = false;
   @Override
   protected String doInBackground(String... urls) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response;
    String responseString = null;
    try {
        //String url = URLEncoder.encode(urls[0]);
        HttpPost httpPost = new HttpPost(urls[0]);
        response = httpclient.execute(httpPost);
        StatusLine statusLine = response.getStatusLine();
        switch (statusLine.getStatusCode()) {
            case HttpStatus.SC_OK:
            case HttpStatus.SC_NOT_FOUND:
            case HttpStatus.SC_EXPECTATION_FAILED:
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                responseString = out.toString();
                break;
            default:
                //Closes the connection.
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
        }
        if (testURLConnection) { // testing same url works fine
            URL oracle = new URL(urls[0]);
            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    yc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                responseString += inputLine;
            in.close();
        }
    } catch (ClientProtocolException e) {
        Helper.logExceptionToFile(e);
        e.printStackTrace();
    } catch (IOException e) {
        Helper.logExceptionToFile(e);
        e.printStackTrace();
    } catch (Exception e) {
        Helper.logExceptionToFile(e);
        e.printStackTrace();
       }

    return responseString;
} }

没有错误,但似乎服务器不理解该参数,因为它返回空查询结果,而使用具有相同URL的URLConnection则返回正确的查询响应

0 个答案:

没有答案