Httpclient:Target host is not specified ,目标主机不唯一

Java_Boy_W 2017-02-15 04:08:53
在httpclient 端发送Json格式数据到服务端,是一个简单的分页查询,但是总是报这个错误,求大神指点一下
1.Httpclient端代码如下:
①String invokeCal = HttpClientPool.invokePost("http.car.data",params);//http,car.data是调用的地址,从配置文件读取
http.car.data="http://192.168.1.xx:端口号/项目名/方法名",这个大神都懂
invokePost(String,Map<String,String > params)这个方法代码如下:
王亚 15:19:30
public static String invokePost(String address, Map<String, String> params) throws IOException {
String responseBody = "";
try {
HttpPost httpget = new HttpPost(address);
List<NameValuePair> entity = new ArrayList<NameValuePair>();
for (String key : params.keySet()) {
entity.add(new BasicNameValuePair(key, params.get(key)));
}
httpget.setEntity(new UrlEncodedFormEntity(entity, HTTP.UTF_8));
logger.debug("Executing request " + httpget.getRequestLine());
// Create a custom response handler
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
// return entity != null ?
// convertStreamToString(entity.getContent()) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
}

};
responseBody = httpclient.execute(httpget, responseHandler);
logger.debug("----------------------------------------");
logger.debug(responseBody);
} finally {
// httpclient.close();
}
return responseBody;
}


②服务端代码:
@RestController
@RequestMaping ("/xxxxxx")
public class xxxxx(){
@RequestMaping ("/page")
@ResponseBody
Object page(接收各种参数){

}

}
...全文
3711 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧