首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android端向服务器交付请求的几种方式

2013-09-12 
android端向服务器提交请求的几种方式1、GET方式其实GET方式说白了,就是拼接字符串。。最后拼成的字符串的式

android端向服务器提交请求的几种方式

1、GET方式

其实GET方式说白了,就是拼接字符串。。最后拼成的字符串的格式是: path ?  username= ....& password= ......

public boolean loginByHttpClientPost(String path,String username , String password)throws Exception{HttpClient httpClient = new DefaultHttpClient();HttpPost httpPost = new HttpPost(path);List<NameValuePair> parameters = new ArrayList<NameValuePair>();parameters.add(new BasicNameValuePair("username", username));parameters.add(new BasicNameValuePair("password", password));UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters,"utf-8");httpPost.setEntity(entity);HttpResponse httpResponse = httpClient.execute(httpPost);    if(httpResponse.getStatusLine().getStatusCode() == 200){    return true;    }        return false;}


热点排行