Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中的网站邮件登录_Android_Login_Web - Fatal编程技术网

Android中的网站邮件登录

Android中的网站邮件登录,android,login,web,Android,Login,Web,我想创建一个电子邮件登录页,以访问我的网络邮件,而我尝试连接到邮件输入id和密码后,它显示了我的网络邮件登录的html代码,而不是把我带进我的收件箱。这是我的密码\ 主要活动:- 公共类AndroidLogin扩展了活动实现OnClickListener{ 按钮ok,后退,退出; 文本视图结果 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceS

我想创建一个电子邮件登录页,以访问我的网络邮件,而我尝试连接到邮件输入id和密码后,它显示了我的网络邮件登录的html代码,而不是把我带进我的收件箱。这是我的密码\

主要活动:-

公共类AndroidLogin扩展了活动实现OnClickListener{

按钮ok,后退,退出; 文本视图结果

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Login button clicked
    ok = (Button)findViewById(R.id.btn_login);
    ok.setOnClickListener(this);

    result = (TextView)findViewById(R.id.lbl_result);

}

public void postLoginData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();

    /* login.php returns true if username and password is equal to saranga */
    HttpPost httppost = new HttpPost("http://www.gowdanar.com:2095/");

    try {
        // Add user name and password
     EditText uname = (EditText)findViewById(R.id.txt_username);
     String username = uname.getText().toString();

     EditText pword = (EditText)findViewById(R.id.txt_password);
     String password = pword.getText().toString();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        Log.w("SENCIDE", "Execute HTTP Post Request");
        HttpResponse response = httpclient.execute(httppost);

        String str = inputStreamToString(response.getEntity().getContent()).toString();
        Log.w("SENCIDE", str);

        if(str.toString().equalsIgnoreCase("true"))
        {
         Log.w("SENCIDE", "TRUE");
         result.setText("Login successful");  
        }else
        {
         Log.w("SENCIDE", "FALSE");
         result.setText(str);            
        }

    } catch (ClientProtocolException e) {
     e.printStackTrace();
    } catch (IOException e) {
     e.printStackTrace();
    }
}

private StringBuilder inputStreamToString(InputStream is) {
 String line = "";
 StringBuilder total = new StringBuilder();
 // Wrap a BufferedReader around the InputStream
 BufferedReader rd = new BufferedReader(new InputStreamReader(is));
 // Read response until the end
 try {
  while ((line = rd.readLine()) != null) {
    total.append(line);
  }
 } catch (IOException e) {
  e.printStackTrace();
 }
 // Return full string
 return total;
}

@Override
public void onClick(View view) {
  if(view == ok){
    postLoginData();
  }
}
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//单击登录按钮
ok=(按钮)findViewById(R.id.btn\u登录);
好的,setOnClickListener(这个);
结果=(TextView)findViewById(R.id.lbl_结果);
}
public void postloginanda(){
//创建一个新的HttpClient和Post头
HttpClient HttpClient=新的DefaultHttpClient();
/*如果用户名和密码等于saranga,login.php将返回true*/
HttpPost HttpPost=新的HttpPost(“http://www.gowdanar.com:2095/");
试一试{
//添加用户名和密码
EditText uname=(EditText)findViewById(R.id.txt_用户名);
字符串username=uname.getText().toString();
EditText pword=(EditText)findViewById(R.id.txt_密码);
字符串密码=pword.getText().toString();
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“用户名”,username));
添加(新的BasicNameValuePair(“密码”,password));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
w(“SENCIDE”,“执行HTTP Post请求”);
HttpResponse response=httpclient.execute(httppost);
字符串str=inputStreamToString(response.getEntity().getContent()).toString();
Log.w(“SENCIDE”,str);
if(str.toString().equalsIgnoreCase(“true”))
{
Log.w(“SENCIDE”、“TRUE”);
result.setText(“登录成功”);
}否则
{
Log.w(“SENCIDE”、“FALSE”);
结果:setText(str);
}
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}
私有StringBuilder inputStreamToString(InputStream为){
字符串行=”;
StringBuilder总计=新StringBuilder();
//在InputStream周围包装一个BufferedReader
BufferedReader rd=新的BufferedReader(新的InputStreamReader(is));
//读取响应直到结束
试一试{
而((line=rd.readLine())!=null){
合计.追加(行);
}
}捕获(IOE异常){
e、 printStackTrace();
}
//返回完整字符串
返回总数;
}
@凌驾
公共void onClick(视图){
如果(视图==ok){
postloginanda();
}
}

}

将http请求放在AsynTask中,然后像这样在onPostExecute()方法中获取响应

私有类GetResult扩展了异步任务{

    @Override
    protected String doInBackground(String... urls) {
        Log.v(TAG + ".doInBackground", "doInBackground method call");
        String response1 = null;

    /*  for (String url : urls) {
            WebHelper webHelper = new WebHelper();
            response = webHelper.getResult(url);
            Log.v(TAG+".doInBackground", "json response is:" + response);
        }*/

           HttpClient httpclient = new DefaultHttpClient();
           HttpPost  httppost = new HttpPost(""http://www.gowdanar.com:2095/"");
          //  Log.d("response", "WORKING");
            try {


                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

                nameValuePairs.add(new BasicNameValuePair("username", username));
                nameValuePairs.add(new BasicNameValuePair("password", password));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                InputStream is = response.getEntity().getContent();
                WebHelper webHelper = new WebHelper();
                response1 = webHelper.convertStreamToString(is);
                Log.v(TAG+".doInBackground", "json response is:" + response1);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return response1;


    }

    @Override
    protected void onPostExecute(String result) {

        Log.v(TAG + ".onPostExecute", "onPostExecute method call");
        dialog.dismiss();
        Log.v(TAG+".onPostExecute", "json response is:" + result);


         if(result!=null){

            try {
                //JSONTokener tokener = new JSONTokener(result);
                JSONObject resultObjct = new JSONObject(result);
                String user_id=resultObjct.getString("User_ID");


                }

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

    }
}
@覆盖
受保护的字符串doInBackground(字符串…URL){
Log.v(TAG+“.doInBackground”、“doInBackground方法调用”);
字符串response1=null;
/*for(字符串url:url){
WebHelper WebHelper=新的WebHelper();
response=webHelper.getResult(url);
Log.v(TAG+“.doInBackground”,“json响应为:”+response);
}*/
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“”)http://www.gowdanar.com:2095/"");
//日志d(“响应”、“工作”);
试一试{
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“用户名”,username));
添加(新的BasicNameValuePair(“密码”,password));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
InputStream is=response.getEntity().getContent();
WebHelper WebHelper=新的WebHelper();
response1=webHelper.convertStreamToString(is);
Log.v(TAG+“.doInBackground”,“json响应为:”+response1);
}捕获(客户端协议例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回响应1;
}
@凌驾
受保护的void onPostExecute(字符串结果){
Log.v(标记+“.onPostExecute”,“onPostExecute方法调用”);
dialog.dismise();
Log.v(TAG+“.onPostExecute”,“json响应为:”+result);
如果(结果!=null){
试一试{
//JSONTokener令牌=新的JSONTokener(结果);
JSONObject resultObjct=新的JSONObject(结果);
String user_id=resultObjct.getString(“user_id”);
}
}捕获(JSONException e){
e、 printStackTrace();
}
捕获(例外e){
e、 printStackTrace();
}
}
}
}