【发布时间】:2014-04-01 04:41:22
【问题描述】:
我知道这个问题已经被问过很多次了,但是这些问题的答案对我没有用。
我正在尝试访问 REST API,但是当我尝试连接时出现此错误:
java.lang.IllegalArgumentException: Host name may not be null
我的网址是“http:localhost:3000/api/v1/users”,
我的代码:
public String post(List<NameValuePair> data) {
String result = null;
HttpPost request;
try {
request = new HttpPost("http:localhost:3000/api/v1/users");
ResponseHandler<String> handler = new BasicResponseHandler();
try {
result = client.execute(request, handler);
client.getConnectionManager().shutdown();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return result;
}
【问题讨论】:
-
你在浏览器中检查这个 http:localhost:3000/api/v1/users 吗?
标签: android rest httpclient