0

I've been searching a lot, however haven't find any solution. I want to use URL, HttpsUrlConnection instead of deprecated ones (HttpClient, HttpPost, DefaultHttpClient). I have this code below so far:

Note "MyUrl" takes some parameters. See question 2.

 URL url = new URL("MyUrl");
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    /*Here exception occurs!*/
    connection.connect();

So, I have 2 problems to solve: (Maybe the 2nd one should be solved 1stly. I have no idea...)

  1. When I use connection.someMethod(); SSLException occurs. (i.e connection.getResponseCode();)

The Error is :

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x635cb550: Failure in SSL library, usually a protocol error

  1. What is alternative way of List<NameValuePair> & BasicNameValuePair ? Those are deprecated as well.
Alvin
  • 894
  • 8
  • 16

2 Answers2

1

You can use following library for HTTP requests-response

You can use Google-Gson for parsing JSON data

Jenisha Makadiya
  • 832
  • 5
  • 17
0

You don't need to use connect. Simply doing this:

 conn.setRequestMethod("POST");
 InputStream in = new BufferedInputStream(conn.getInputStream());
 response = org.apache.commons.io.IOUtils.toString(in, "UTF-8"); 

You will get your response.

Also, you can use ContentValues as a replacement for NameValuePair:

ContentValues initialValues = new ContentValues();
initialValues.put("parameter", value);
Fustigador
  • 6,339
  • 12
  • 59
  • 115