即使登录成功,Android也无法访问网页内容

时间:2013-11-23 06:26:10

标签: android asp.net web-services android-intent login

我使用我编码的应用程序登录公司网页时遇到问题。当我使用toast消息时,它可以判断登录是否成功。但是当我插入INTENT并转移到下一个将查看网页内容的活动时(成功登录后)我只能查看公司的“LOGIN WEBPAGE”,而不是内容。我非常感谢您提供正确的代码或添加到我的代码中。提前谢谢。

以下是我的代码:

这是我们公司的网页:http://www.allianceinmotion.com/members.asp

登录活动:

package com.example.packagename;

imports ..... ;

public class LoginActivity extends Activity implements OnClickListener {

private ProgressDialog pDialog; 
private static final String LOGIN_URL = "http://vo.aimglobalinc.com/control/con_login.asp";
JSONParser jsonParser = new JSONParser(); 
Boolean isInternetPresent = false;

private EditText user, pass;
private Button mSubmit, mRegister;
ConnectionDetector cd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    Intent i1 = getIntent();
    i1.getExtras().getInt("login");
    setResult(RESULT_OK, i1);

    cd = new ConnectionDetector(getApplicationContext());

    user = (EditText)findViewById(R.id.txt_username);
    pass = (EditText)findViewById(R.id.txt_password);

    mSubmit = (Button)findViewById(R.id.btn_login);
    mRegister = (Button)findViewById(R.id.btn_register);

    mSubmit.setOnClickListener(this);
    mRegister.setOnClickListener(this);

}

        @Override
        public void onClick(View v) {
            isInternetPresent = cd.isConnectingToInternet(); 
            switch (v.getId()) {
            case R.id.btn_login:
                if (isInternetPresent) {
                    new AttemptLogin().execute();

                }else {
                    Toast.makeText(LoginActivity.this, "This requires an internet connection.", Toast.LENGTH_LONG).show();
                }
                break;

            case R.id.btn_register:
                //Intent i = new Intent(this, RegisterActivity.class);
                //startActivity(i);
                break;
            default:
                break;
            }
        }


        class AttemptLogin extends AsyncTask<String, String, String> {

            boolean failure = false;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(LoginActivity.this);
                pDialog.setMessage("Attempting to login...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.show();

            }
            @Override
            protected String doInBackground(String... args) {
                String username = user.getText().toString();
                String password = pass.getText().toString();

                try {

                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                    params.add(new BasicNameValuePair("uname", username));
                    params.add(new BasicNameValuePair("pword", password));

                    Log.d("request!", "starting");

                    JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params);

                    Log.d("Login attempt", json.toString());

                    return json.getString("success");

                } catch (JSONException e) {
                    e.printStackTrace();
                }


                return null;

            }
            /**
            * After completing background task Dismiss the progress dialog
            * **/

            protected void onPostExecute(String result) {
                super.onPostExecute(result);

                pDialog.dismiss();

                if (result.equals("true")) {
                    Toast.makeText(LoginActivity.this, "Login Successful!", Toast.LENGTH_LONG).show();

                    Intent i = new Intent(LoginActivity.this, MyAccounts.class); 
                    finish();
                    startActivity(i);

                } else {
                    Toast.makeText(LoginActivity.this, "Please enter the correct username and password.", Toast.LENGTH_LONG).show();

                }

            }

        }

}

MYACCOUNTS ACTIVITY(我想在成功登录后访问页面内容)

package com.example.packagename;

imports ..... ;


public class MyAccounts extends Activity {

private WebView mWebView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    mWebView = new WebView(this);
    mWebView.loadUrl("http://www.allianceinmotion.com/members.asp");
    //mWebView.loadUrl("http://vo.aimglobalinc.com/r2bs.asp");
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    this.setContentView(mWebView);
}

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
        mWebView.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
  }
}

使用jsonlint.org,当我从LOGIN活动验证URL时,输出如下:

{
"success": "failed",
"message": "Invalid username or password"
 }

0 个答案:

没有答案