【发布时间】:2012-06-12 13:16:53
【问题描述】:
我有一个抛出 null 异常的 HTTP 请求。
代码如下:
public String updateRounds() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://technet.rapaport.com/HTTP/Prices/CSV2_Round.aspx");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Username", _user));
nameValuePairs.add(new BasicNameValuePair("Password", _password));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = "";
// Execute HTTP Post Request
try {
response = httpclient.execute(httppost, responseHandler); // it gets
// exception
// here
} catch (Exception e) {
e.getMessage(); // e is null
}
return response;
}
有人知道为什么会这样吗?
【问题讨论】:
-
您的应用程序是否获得了 UsesInternet 权限?还可以尝试捕获 httpclient 可以抛出的其他类型的异常,而不是泛型类型
标签: android http-request