gpt4 book ai didi

android - 没有得到响应 response = httpclient.execute(request);

转载 作者:搜寻专家 更新时间:2023-11-01 08:13:45 25 4
gpt4 key购买 nike

public class HTTPPoster {
public static HttpResponse doPost(String url, JSONObject c) throws ClientProtocolException, IOException
{

HttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);

HttpEntity entity;
StringEntity s = new StringEntity(c.toString());
s.setContentEncoding((Header) new BasicHeader(HTTP.DEFAULT_CONTENT_CHARSET, "application/json"));
entity = s;
request.setEntity(entity);

HttpResponse response;

response = httpclient.execute(request);

return response;
}

}

这是代码,但在 response = http.client.execute(request) 上没有得到响应。我找不到原因。

最佳答案

您应该异步调用该方法。然后它将使用相同的代码。将这两行代码添加到你的项目中

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

和将最低 sdk 版本设置为 9

关于android - 没有得到响应 response = httpclient.execute(request);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939122/

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