このページにログインしようとしています: https://eas.admin.uillinois.edu/eas/servlet/EasLogin?redirect=https://webprod.admin.uillinois.edu/ssa/servlet/SelfServiceLogin?appName=edu .uillinois.aits.SelfServiceLogin&dad=BANPROD1
Android で HttpPost を使用する。私はオンラインで見て、httpclient を試し、httppost を実行しました。ただし、応答は同じ URL です。これが私のコードです。何が必要ですか? ありがとう。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_balance);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
String username = getIntent().getExtras().getString("username");
String password = getIntent().getExtras().getString("password");
//Building post parameters, key and value pair
List<NameValuePair> accountInfo = new ArrayList<NameValuePair>(2);
accountInfo.add(new BasicNameValuePair("inputEnterpriseId", username));
accountInfo.add(new BasicNameValuePair("password", password));
//Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
//Creating HTTP Post
HttpPost httpPost = new HttpPost(LOGIN_URL);
/* Not needed?
BasicHttpParams params = new BasicHttpParams();
params.setParameter("ENT_ID", username);
params.setParameter("PASSWORD", password);
httpPost.setParams(params);
*/
//Url Encoding the POST parameters
try {
httpPost.setEntity(new UrlEncodedFormEntity(accountInfo));
}
catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
startActivity(new Intent(this, InputAccountActivity.class));
}
HttpResponse response = null;
InputStreamReader iSR = null;
String source = null;
// Making HTTP Request
try {
response = httpClient.execute(httpPost);
source = inputStreamToString(response.getEntity().getContent()).toString(); //gets website source
// writing response to log
Log.d("Http Response:", response.toString());
Log.d("hi", source);
/*
iSR = new InputStreamReader(response.getEntity().getContent());
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.d("RESPONSE",resEntity.toString());
}
BufferedReader br = new BufferedReader(iSR);
source = "";
while((source = br.readLine()) != null)
{
source += br.readLine();
Log.d(TAG,source.trim());
}
*/
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
startActivity(new Intent(this, InputAccountActivity.class));
}
}