httpclient_get_post

来源:互联网 发布:广联达计价软件 编辑:程序博客网 时间:2024/06/03 20:13
public class UlistClient {public static String getClient(String name,String passrword){String path="http://172.20.74.26:8080/fuwuqi/Fuwuqi?name="+name+"&preass="+passrword;HttpClient client=new DefaultHttpClient();HttpGet get=new HttpGet(path);try {HttpResponse response = client.execute(get);if (response.getStatusLine().getStatusCode()==200) {return EntityUtils.toString(response.getEntity());}} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}public static String PostClient(String name, String password) {String path="http://172.20.74.26:8080/fuwuqi/Fuwuqi";HttpClient client=new DefaultHttpClient();try {HttpPost post=new HttpPost(path);List<NameValuePair> parameters=new ArrayList<NameValuePair>();parameters.add(new BasicNameValuePair("name",name));parameters.add(new BasicNameValuePair("preass",password));HttpEntity entity=new UrlEncodedFormEntity(parameters);post.setEntity(entity);HttpResponse response = client.execute(post);if (response.getStatusLine().getStatusCode()==200) {return EntityUtils.toString(response.getEntity());}} catch (ClientProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return null;}}

0 0