gpt4 book ai didi

java - 使用安全的 SSL 连接保存 session

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:03 25 4
gpt4 key购买 nike

在那里我连接到授权页面,进入帐户并加载主页。如何在不断开连接的情况下下载帐户中的其他页面?这是对的吗?

主类:

HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 10000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 10000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

HttpClient client = new MyHttpClient(httpParameters, getApplicationContext());
HttpPost request = new HttpPost("https://some.com/Login.aspx");

BufferedReader in = null;
try {

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("uname", "name"));
nameValuePairs.add(new BasicNameValuePair("upass", "pass"));
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));

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 page = sb.toString();

textview.setText(page);

} catch (ClientProtocolException e) {...}

MyHttpClient 类:

public class MyHttpClient extends DefaultHttpClient 
{
final Context context;
public MyHttpClient(HttpParams hparms, Context context)
{
super(hparms);
this.context = context;
}

@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}
}

最佳答案

使用相同的请求对象(HttpPost),它应该使用相同的连接,除非你在它上面显式地调用releaseconnection。引用http://hc.apache.org/httpcomponents-client-ga/quickstart.html

关于java - 使用安全的 SSL 连接保存 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14879975/

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