I'm using Guzzle 3, as it's the only version that works on PHP 5.3.2.
I'm having problems sending a POST request, and it appears it's not actually sending the post data. The API works fine. I am able to use Postman to get results when using the correct API key and user ID, but from my script I am not.
What am I doing wrong? I am following the Guzzle documentation:
$client = new Guzzle\Http\Client("http://example.com/api");
# Make API request to get session data
$request = $client->post('user/session', array(
'body' => array(
'token' => $_SESSION['ER']['API_KEY'],
'user' => $_SESSION['ER']['USER_ID']
)
));
$response = $request->send();
var_dump($_SESSION['ER']['API_KEY']);
var_dump($_SESSION['ER']['USER_ID']);
\\ string(32) "a559d5bba5a9e9517d5c3ed7aeb62db6"
\\ string(5) "30972"
When I var_dump
$_POST['token']
on the API, it's not even set. Yet if I run the request in Postman, it works.
Any advice on this please? I am really struggling to see what I'm doing wrong with this request.
I've faced the same problem and fixed it by calling post like:
$request = $client->post(
'user/session',
// this is array of headers
null,
// this is dedicated field with body to post
array(
'token' => $_SESSION['ER']['API_KEY'],
'user' => $_SESSION['ER']['USER_ID']
)
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.