gpt4 book ai didi

android - SSL HttpClient 连接中的 session 过期错误

转载 作者:行者123 更新时间:2023-11-30 02:34:15 25 4
gpt4 key购买 nike

我正在将网站转换为 Android 应用程序。

相同的代码适用于 http URL & 我可以重复使用相同的 session ID。

但在 https 中我收到 session 过期错误。

               HttpPost get3 = new HttpPost(titleURL);
entity = new StringEntity("{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":{\"model\":\"job.order\",\"fields\":[\"job_code\",\"sale_order_id\",\"partner_id\",\"ins_postcode\",\"client_order_ref\",\"cust_po_ref_blanket\",\"engineer_id\",\"appointment\",\"state\"],\"domain\":[[\"state\",\"=\",[\"draft\",\"confirmed\",\"installed\",\"onhold\",\"reject\",\"accepted\"]]],\"context\":{\"lang\":\"en_US\",\"tz\":false,\"uid\":1,\"search_default_open_job\":1,\"bin_size\":true},\"offset\":0,\"limit\":80,\"sort\":\"\",\"session_id\":\"3dcfe71efba0403ba454cef4d390f1fb\"},\"id\":\"r105\"}");
get3.setHeader("Content-Type", "application/json");
get3.setHeader("Cookie:","session_id=3dcfe71efba0403ba454cef4d390f1fb");
get3.setEntity(entity);
trustAll();
HttpClient client = new DefaultHttpClient();

responseBody3 = client.execute(get3, responseHandler);

我的 logcat 错误,

引发 SessionExpiredException(\"Session expired\")\nSessionExpiredException: Session expired\n", "type": "client_exception"}}}

注意:我的登录 URL 正确执行。但我不能将我的 session ID 重新用于其他 URL。

有人帮帮我吗?

最佳答案

我这样做是为了从 https url 下载 apk 文件,你可以根据你的要求修改

第 1 步:建立连接后在第一个 Activity 中创建 DefaultHttpClient 实例。

public static DefaultHttpClient httpClient;

第二步:第一次连接

URL url=new URL(urlToHit);
LoginScreen.httpClient = new DefaultHttpClient();

HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost);

xr.parse(new InputSource(url.openStream()));

第 3 步:现在对于所有进一步的连接,使用相同的 httpClient 例如在下一个 Activity 中:

URL url=new URL(urlToHit);

HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost);


HttpEntity entity = response.getEntity();

InputStream instream = null;

if (entity != null) {
instream = entity.getContent();
}
xr.parse(new InputSource(instream)); //SAX parsing

关于android - SSL HttpClient 连接中的 session 过期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26837291/

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