资源简介

HttpClient工具类,很详细,能拿来就用。

资源截图

代码片段和文件信息

package com.http;



/**
 * 使用代理 请求会经过代理
 * title:百度地图服务类 

 * 版权: Copyright (c) 2011-2016

 * 
 * @author:Administrator

 * @date:Apr 7 2016

 */
public class BaiduMapProxyService {

/**
 * 代理发送请求
 */
private  HttpClientUtil httpClientUtil=new HttpClientUtil(“127.0.0.1“8888);

public String insertLocation(String title String longitude
String latitude String address) {

//插入数据接口
String url = “http://api.map.baidu.com/geodata/v3/poi/create“;

Request request=new Request();
//数据
request.setProperty(“url“ url);
request.setProperty(“method“ “post“);

//我自己的百度云数据库名称
request.setParam(“geotable_id“ “137287“);
request.setParam(“ak“ “GShGXR4uNroTq4mzqsf1v7h3VgsC3aIk“);
request.setParam(“latitude“ latitude);
request.setParam(“longitude“ longitude);
request.setParam(“address“ address);
request.setParam(“coord_type“ “3“);

request.setParam(“title“ title);

Response response;
try {
response = httpClientUtil.sendRequest(request);
if(response==null||response.getStatusCode()!=200){
return null;
}
String content =response.getContentString(“utf-8“);
System.out.println(“返回的数据是:“+content);
return content;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;

}

/**
 * 根据经纬度查周边学校半径500米
 * 
 * @return
 */
public String findNearBySchool(String longitude String latitude) {
String url = “http://api.map.baidu.com/geosearch/v3/nearby?geotable_id=137287&ak=GShGXR4uNroTq4mzqsf1v7h3VgsC3aIk&radius=500&location=“
+ longitude + ““ + latitude;



Request request=new Request();
request.setProperty(“url“ url);
request.setProperty(“method“ “get“);

Response response=new Response();

try {
response = httpClientUtil.sendRequest(request);
if(response==null||response.getStatusCode()!=200){
return null;
}

String content =response.getContentString(“utf-8“);
System.out.println(“返回数据:“+content);
return content;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;

}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        1433  2016-05-15 21:20  HttpClient\.classpath
     文件         562  2016-05-15 21:19  HttpClient\.project
     文件          93  2016-05-15 21:20  HttpClient\.settings\org.eclipse.core.resources.prefs
     文件         243  2016-05-15 21:20  HttpClient\.settings\org.eclipse.jdt.core.prefs
     文件          90  2016-05-15 21:19  HttpClient\.settings\org.eclipse.m2e.core.prefs
     文件        1378  2016-05-15 22:20  HttpClient\pom.xml
     文件        2372  2016-05-15 22:19  HttpClient\src\main\java\com\http\BaiduMapProxyService.java
     文件        2520  2016-05-15 22:29  HttpClient\src\main\java\com\http\BaiduMapService.java
     文件       19076  2016-05-15 22:17  HttpClient\src\main\java\com\http\HttpClientUtil.java
     文件        2356  2016-05-15 22:13  HttpClient\src\main\java\com\http\Request.java
     文件        1446  2016-05-15 21:39  HttpClient\src\main\java\com\http\Response.java
     文件        1639  2016-05-15 22:29  HttpClient\src\main\java\com\http\StringUtils.java
     目录           0  2016-05-15 22:54  HttpClient\src\main\resources\
     文件        1134  2016-05-15 22:30  HttpClient\src\test\java\com\http\test\T.java
     目录           0  2016-05-15 22:54  HttpClient\src\test\resources\
     文件        2710  2016-05-15 22:20  HttpClient\target\classes\com\http\BaiduMapProxyService.class
     文件        2684  2016-05-15 22:29  HttpClient\target\classes\com\http\BaiduMapService.class
     文件        1029  2016-05-15 22:20  HttpClient\target\classes\com\http\HttpClientUtil$1.class
     文件        1788  2016-05-15 22:20  HttpClient\target\classes\com\http\HttpClientUtil$2.class
     文件        1822  2016-05-15 22:20  HttpClient\target\classes\com\http\HttpClientUtil$3.class
     文件       17747  2016-05-15 22:20  HttpClient\target\classes\com\http\HttpClientUtil.class
     文件        2695  2016-05-15 22:20  HttpClient\target\classes\com\http\Request.class
     文件        2067  2016-05-15 22:20  HttpClient\target\classes\com\http\Response.class
     文件        1567  2016-05-15 22:29  HttpClient\target\classes\com\http\StringUtils.class
     文件        1239  2016-05-15 22:30  HttpClient\target\test-classes\com\http\test\T.class

评论

共有 条评论