6
回答
php如何和Android应用交互,实现登陆,通信等
滴滴云服务器,限时包月0.9元,为开发者而生>>>   
login.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				
				final String ID=userID.getText().toString();
				final String pwd=password.getText().toString();
				
				//用于判断输入框的内容
				if(!ID.equals("")&&!pwd.equals("")){
					
						new Thread(){
							@Override
							public void run(){
								HttpPost httpPost=new HttpPost("http://218.192.123.81:82/CI_2/index.php/Validate/login");
								
								//插入数据
								List<NameValuePair> params=new ArrayList<NameValuePair>();
								params.add(new BasicNameValuePair("userID",ID));
								params.add(new BasicNameValuePair("passwd",pwd));
								
								
								
								try {
									//设置请求参数
									httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
									//发送请求
									HttpResponse response=httpClient.execute(httpPost);
									
									//如果请求成功
									if(response.getStatusLine().getStatusCode()==200){
										BufferedReader reader=new BufferedReader(new InputStreamReader
												(response.getEntity().getContent()));
										
										String s;
										StringBuffer sb=new StringBuffer();
										while((s=reader.readLine())!=null)
											sb.append(s);
										
				
										/*
										 * 初始化数据路
										 */
										SQLiteDatabase db=SQLiteDatabase.openOrCreateDatabase(MainLogin.this.getFilesDir().toString()
												+"/contentHistory.db", null);
										db.execSQL("create table user_content(_id integer primary key autoincrement,"
												+ "content varchar(100))");
										
										Bundle bundle=new Bundle();
										bundle.putString("response", sb.toString());
										
										Intent intent=new Intent(MainLogin.this,Home.class);
										intent.putExtra("response", bundle);
										
										startActivity(intent);
										finish();
									}
									
								} catch (Exception e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						};
				}
			}

        });//登陆按钮函数结束



<?php

class Validate extends CI_Controller{
	public function login(){
		
		
		$ID=$this->input->post('userID');
		$passwd=$this->input->post('passwd');
		
		if($ID!=''&&$passwd!=''){
			echo json_encode(array('response'=>'login'));
		}
		
		
	}



Android应用如何和php后台进行交互,实现登陆,转发登陆的功能。测试了一下,好像没什么反应,求帮助,指教。
举报
yuhuajie
发帖于3年前 6回/3K+阅
顶部