@Override
protected Void doInBackground(String... strings) {
String JSPN_Request = "";
String response = "";
URL url = null;
JSONObject jsonObject = null;
HttpURLConnection conn = null;
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
BufferedWriter bufferedWriter = null;
try
{
url = new URL(strings[0]);
jsonObject = new JSONObject();
jsonObject.put("userId",102);
jsonObject.put("id",102);
jsonObject.put("title","hello world");
jsonObject.put("body","hello world");
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
outputStreamWriter = new OutputStreamWriter(os);
bufferedWriter = new BufferedWriter(outputStreamWriter);
bufferedWriter.write(jsonObject.toString());
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
conn.setDoInput(true);
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null) {
sb.append(line);
break;
}
reader.close();
response = sb.toString().toString();
}catch (Exception e)
{
Log.d(TAG, "----------------------------------json-error----------------------------------");
Log.d(TAG, "POSTING ERROR" + e);
Log.d(TAG, "----------------------------------json-error----------------------------------");
}}
when i trying to post to database i get this error and i searched alot but nothing. i'm using localhost to post this data using url (10.0.3.0:8000/post) as i'm using genymotion emulator thanks in advance.