1

这是我的代码

public class RequestTask extends AsyncTask<String, String, String>{

@Override
protected String doInBackground(String... uri) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response;
    String responseString = null;
    try {
        HttpGet get = new HttpGet(uri[0]);
        Log.v("test","start RESPONSE");
        response = httpclient.execute(get);
        StatusLine statusLine = response.getStatusLine();
        if(statusLine.getStatusCode() == HttpStatus.SC_OK){
            Log.v("test","status complete");
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            response.getEntity().writeTo(out);
            out.close();
            responseString = out.toString();
        } else{
            response.getEntity().getContent().close();
            throw new IOException(statusLine.getReasonPhrase());
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return responseString;
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
}

}

当 uri[0] = " http://www.google.com " 时,它没有错误并且 Log.v("test","status complete") 显示。但当

uri[0] = "http://best12t.gosoft.com/web_service/counter/CSTrack2.aspx?cli=focusgroup&cam=androidtest&1=W_S_UID&2=W_S_SC&3=W_S&5=W_S_DATE&7=www.gocorp.com&8=www.gocorp.com%2Ftc%2F&9=&10=W_S_IP&11=www.gocorp.com&12=www.gocorp.com%2F&13=&14=website&15=W_S&16=W_S&17=W_S&19=windows&20=Win%207(x64)&21=1&22=9.0&23=1366x768&24=1&25=1&6=CRM%20%26%20%u6578%u4F4D%u884C%u92B7%u7684%u9818%u5C0E%u8005%20-%20MIGO%20CORP%20%u529F%u5178%u96C6%u5718%20&1375088741345"

发生错误,我的虚拟设备停止并出现“不幸的是,应用程序已停止”。此外,Log.v("test","start RESPONSE") 没有显示在我的 LogCat 上。

我尝试了另一个应用程序在网络浏览器上输入此 url,它可以工作,并且我可以从我的网络获取此消息。

那么使用httpget有什么限制吗?

感谢帮助!

4

0 回答 0