Reputation: 894
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...)
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
List<NameValuePair> & BasicNameValuePair
? Those are deprecated as well. Upvotes: 0
Views: 2215
Reputation: 6459
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);
Upvotes: 0
Reputation: 832
You can use following library for HTTP requests-response
You can use Google-Gson for parsing JSON data
Upvotes: 1