0

我正在尝试登录此页面: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));
    }    
}
4

1 回答 1

0

我只是猜测,尝试改变

accountInfo.add(new BasicNameValuePair("inputEnterpriseID", username));

到下面给定的代码。

accountInfo.add(new BasicNameValuePair("inputEnterpriseId", username));

我认为您的 ID 不正确。希望这会有所帮助

于 2012-12-07T06:07:00.790 回答