gpt4 book ai didi

android - 使用 HttpResponse 时出现异常 response = client.execute(request);

转载 作者:行者123 更新时间:2023-11-30 02:18:03 26 4
gpt4 key购买 nike

我正在尝试和这个人做同样的事情 here我正在使用 AsyncTask 调用 executeHttpPost。但是,通过调试应用程序,当它到达行时

HttpResponse response = client.execute(request);

它跳过所有内容到行

if (in != null) {

我很确定该 URL 有效。

public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
HttpResponse response = client.execute(request);
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 (IOException e) {
e.printStackTrace();
}}}}
public static String executeHttpGet(String url) throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = client.execute(request);
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 (IOException e) {
e.printStackTrace();
}}}}}

日志:

W/ActivityThread﹕ Application is waiting for the debugger on port 8100...
I/System.out﹕ Sending WAIT chunk
I/art﹕ Debugger is active
Debugger has connected
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ waiting for debugger to settle...
I/System.out﹕ debugger has settled (1496)
I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: QUALCOMM Build: 10/24/14, 167c270, I68fa98814b
I/OpenGLRenderer﹕ Initialized EGL, version 1.4
I/Choreographer﹕ Skipped 429 frames! The application may be doing too much work on its main thread.
I/Choreographer﹕ Skipped 38 frames! The application may be doing too much work on its main thread.
I/Choreographer﹕ Skipped 37 frames! The application may be doing too much work on its main thread.
I/Choreographer﹕ Skipped 30 frames! The application may be doing too much work on its main thread.
I/Choreographer﹕ Skipped 703 frames! The application may be doing too much work on its main thread.
I/Choreographer﹕ Skipped 3307 frames! The application may be doing too much work on its main thread.

最佳答案

问题解决了,我添加了权限

<uses-permission android:name="android.permission.INTERNET" />

AndroidManifest.xml

关于android - 使用 HttpResponse 时出现异常 response = client.execute(request);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28973202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com