我有一个抛出 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;
}

任何人都知道为什么会发生这种情况?

最佳答案

谢谢大家的帮助。
我已经改变了

e.getMessage();


e.printStackTrace();

我看到异常(exception)是关于 ssl 证书。
所以我处理了它,现在它起作用了。
谢谢你们。

关于android - android中的httprequest失败并且异常为空,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10997501/

10-12 00:30
查看更多