2

Am using okhttp to send and receive data to and from the server not working as expected or am I doing something wrong.

My Android Client Side, bear in mind I have already instantiated the client okHttp object and my containing class already implements the .enqueue asynchronous methods.

JSONObject obj = new JSONObject();
obj.put("usr", "alex");
final MediaType JSON
        = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, json);
request = new Request.Builder()
                        .url(config.SERVER_GET_RECEIPTS)
                        .post(body)
                        .build();
client.newCall(request).enqueue(this);

The response from my server side is a string I put in place if the $_POST variable is empty. and it returns this string.

if(!empty($_POST)){
    echo "Properly Parsed" . $_POST['usr'];
}else{
    echo "Not Properly Parsed";
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
DaviesTobi alex
  • 610
  • 1
  • 9
  • 34

1 Answers1

1

When calling the RequestBody.create(JSON, json); you should send obj.toString() as the json parameter, so at the end it would be something like this RequestBody.create(JSON, obj.toString());

d3vCr0w
  • 602
  • 1
  • 5
  • 11