3
votes

I should send some JSON in my Get request and the server returns some data in application/json as response:

$url='http://example.com/var1=123&var2={'id':123,satrt:342,end:987,using:"abc"}';

and I use this code:

$client = new \GuzzleHttp\Client;
$response = $client->get($url);
$data = json_decode((string)$response->getBody(), true);

but it send a request to:

 http://example.com/var1=123&var2=%7B'id':123,satrt:342,end:987,using:"abc"%7D

I see this answer about $response->getQuery()->useUrlEncoding(false) but it do nothing.

how can I tell GuzzleHttp not to url encode the { and }?

1
I've just enjoyed myself a third-party API server that not only expects a GET request with a malformed URL but will also not work with the equivalent well-formed URL. I guess this is the same situation.Álvaro González
also having server issue with bracesMladen Janjetovic

1 Answers

0
votes

IMO you should not want to do that. The remote server must decode the query string, so it will receive the original string in the end. BTW, it's better to use query option to manage query string parameters.

If you want to do it anyway, try to construct an instance of Uri class manually.