I am trying to send a JSON object from my android application to my site's database. However, I seem to not get any type of connection and I don't get any exception errors. I am currently trying to get a connection just with java in eclipse but still no luck.
submitAlbum.php:
<?php
if(isset($_POST["albumId"])){
$albumId = json_decode($_POST["albumId"]);
}
The java Code:
String albumId = "qjlix";
try{
//Creates JSON object
JSONObject tempObj = new JSONObject();
tempObj.put("albumId", albumId);
//Creates connection to URL
URL targetUrl = new URL("http://example.com/submitAlbum.php");
HttpURLConnection conn = (HttpURLConnection) targetUrl.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setConnectTimeout(500);
conn.setRequestProperty("Content_Type", "application/json; charset=UTF-8");
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(tempObj.toString());
writer.flush();
writer.close();
} catch (Exception e){
System.out.println(e.toString());;
}
Is their something I am missing or doing wrong?