Reputation: 83
I'm trying to post a JSON variable and a string variable via HTTP Guzzle. It gives Internal Server Error stating unexpected '
(which is apparently ').
Here is what I have tried so far-
HTTP Guzzle Code
$data = $_GET['data'];
$email = $_GET['email'];
$client = new Client();
$response = $client->request('POST', 'http://someurlhere.com', [
'data' => $data, // this is json variable
'email' => $email // this is string variable
]);
if($response = $request->send()){
// redirect somewhere
}
I have also tried wrapping the JSON variable in 'json' => ['data' => $data]
, but nothing desirable happened and the error remained the same.
Also, the variables are not getting set via a form. So I have not wrapped them inside form_params
.
Upvotes: 0
Views: 343
Reputation: 83
I found what I was doing wrong there. The code is perfect. The only reason that was causing that problem was the errors I had on my other server, where I am doing the POST request.
This answer is just for my future reference and to help many others out there that might be facing the same problem or may face in the coming future.
Upvotes: 1
Reputation: 1062
I think you can use:
//Guzzle version ~6.3
$response = (new Client())->request("post", $uri, [
'json' => $formParams
]);
Check you $uri response directly with post man and resolve problem if it needed.
Upvotes: 0