I am using HttpURLConnection
class to send Post request to my server but its not working, I did the same Post call using DefaultHttpClient
& its work properly, but in android org.apache.http.impl.client.DefaultHttpClient
is deprecated, that's why I am using HttpURLConnection
class. I don't know is anything wrong with the way I am sending the JSON
object or something else.
Below is my code implementation
URL url = new URL(linkPath);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(10000);
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(URLEncoder.encode(jsonObject.toString(), "UTF-8"));
writer.close();
out.close();
urlConnection.disconnect();