登录界面 Andriod简单http get请求(含服务器端)二

</pre><pre name="code" class="java">//本文未对<span style="font-family: Arial, Helvetica, sans-serif;">username、password进行校验,请读者自行添加该部分,如判断是否为空等</span>
public class httpUtils {
	private static final String TAG="httputils";
			
	static String pathString=null;
	public httpUtils() {
		// TODO Auto-generated constructor stub
	};
	public static void sendPost(String username,String password){
		Log.d(TAG, username);
		Log.d(TAG, password);
                //get请求 <span style="font-family: Arial, Helvetica, sans-serif;">192.168.0.179:8080为tomcat搭建地址,每个人不一样,记得修改</span>
<span style="font-family:Arial, Helvetica, sans-serif;">                               // 整个get URI </span><span style="font-family: Arial, Helvetica, sans-serif;">192.168.0.179:8080</span><span style="font-family:Arial, Helvetica, sans-serif;">?</span><span style="font-family: Arial, Helvetica, sans-serif;">username=admin&password=123</span><span style="font-family:Arial, Helvetica, sans-serif;">
</span><span style="font-family:Arial, Helvetica, sans-serif;">
</span>
		pathString="http://192.168.0.179:8080/Myweb/Webdo"+"?"+"username="+username+"&"+"password="+password;
		Log.d(TAG, pathString);	
		//创建httpclient
		HttpClient client=new DefaultHttpClient();
		
	        //创建get请求	
		HttpGet get=new HttpGet(pathString);
		try {
			HttpResponse response=client.execute(get);
                        //获取返回结果 200为请求成功。
			if(response.getStatusLine().getStatusCode()==200)
			{
				
				Log.d(TAG, "sucess!!");
			}
			
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	};

}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。