そこで認証ページに接続し、アカウントにエントリーしてメインページを読み込みます。接続を失わずにアカウント内の他のページをダウンロードするにはどうすればよいですか? そして、それは正しいですか?
メインクラス:
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);
}
}