2

I am having a strange problem and could not figure out how to solve it.I am using webservice from my mobile application to authenticate login details and for that application sends a $_POST data to my api and api returns the data.

Now same code seems to work fine through my mobile but if i test it in postman it doesnt work and my file_get_contents ( "php://input" ) do not return any data.

here is the chunk of code which is not working on my localhost and on server,but the same code works fine on my application. If i request through application than it authenticates the data and let the user log in.

public function getPostdata() {
    $post = file_get_contents ( "php://input" );
    $data = CJSON::decode ( $post, true );
    return $data;
}
4
  • Have you tested without the decode, just dump the contents of php://input? Commented Apr 6, 2016 at 0:48
  • @Devon i do not get any data in $post,i tried using debugger but file_get_contents ( "php://input" ) returns null. Commented Apr 6, 2016 at 0:50
  • Can you please check is any other place where php://input read is used. You can read from this stream only one time. After that it will return only empty. So to check is it works or not(any system issues) - please try to put file_get_contents ( "php://input" ) as first code line in your code Commented Apr 6, 2016 at 3:00
  • @Rinat Yes i have checked that and its the first line of the code. Commented Apr 6, 2016 at 4:30

1 Answer 1

6

Okay, I know it's 2 years later, but I ran into this today while testing with Postman and it was making me crazy. The problem? I didn't have the end slash on the endpoint URL and so a 301 redirect occurred and cleared out php://input.

-.-

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.