I am sending JSON object from my Android app to my server. In my development local machine it works fine. I get the data and decode it. But when I deployed my server to compute engine, I don't receive the data on the server end. The data is sent from the Android client. I also tested the JSON from my browser and I get 200 response code. Here are the code snippets:
//Client
//Create JSONObject here This is the JSON I am sending {"test", "1234"}
JSONObject json = new JSONObject();
json.put("test", args[0]);
String postData=json.toString();
// Send POST output.
OutputStreamWriter os = new OutputStreamWriter(urlConn.getOutputStream(), "UTF-8");
os.write(postData);
Log.e("NOTIFICATION", "Sent");
os.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String msg="";
String line = "";
while ((line = reader.readLine()) != null) {
msg += line;
}
Log.i("msg=",""+msg);
//Server
<?php
$json = file_get_contents("php://input");
var_dump($json); //this returns String(0)
$decoded = json_decode($json, TRUE);
$pasid = $decoded['test'];
echo"test if it works";
var_dump($pasid); //returns null
No matter what I do the Android app sends a string but on the server side I am getting empty string. I can't figure out why so far.