Joginder Sharma
Joginder Sharma

Reputation: 71

How to Extract Request Body at Server Side in PHP send by Retrofit POST request

I am using Retrofit Lib.

My code is

public class TestPostData {
  final String username;
  final String password;

  TestPostData(String username, String password) {
    this.username = username;
    this.password = password;
  }
}

and interface is

    interface Test {
      @POST("/post.php")
      void testMethod(@Body TestPostData postbody,@Query("qName") String qName,Callback<Response> callback);
  }

Rest Adapter

RestAdapter restAdapter = new RestAdapter.Builder()
    .setEndpoint(TEST_URL)
    .setLogLevel(RestAdapter.LogLevel.FULL)
    .build();

and call it as

testObj.testMethod(new TestPostData("myusername", "mypassword"),"myname",new Callback<Response>() { ..............

at the server side i get $_POST array as empty. How to get username and password value at server side. I get the name value.

Upvotes: 2

Views: 1964

Answers (1)

VM4
VM4

Reputation: 6499

I know this is a little bit late, but to read the request body in PHP you can do:

<?php
   echo file_get_contents('php://input');
?>

More about this here.

Upvotes: 5

Related Questions