Search code examples
androidhttp-request

httprequest in android fails and exception is null


I have an HTTP request that throws a null exception.

Here's the code:

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;
}

Anyone has any idea on why this happening?


Solution

  • Thank you all for trying to help. I've changed the

    e.getMessage();
    

    to

    e.printStackTrace();
    

    And I saw that the exception was about ssl certificate. So I handled that and now it works. Thank you all.