kitetail / zttp

A developer-experience focused HTTP client, optimized for most common use cases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the difference between providing post parameters in ‘?foo=bar’ and array?

cornjosh opened this issue · comments

I tried to use Zttp to write a crawler. I found that using two different ways to initiate a POST request would have different results.

Zttp::asFormParams()->post('http://example.com', [
           'foo' => 'bar'
   ];
Zttp::post('http://example.com?foo=boo');

What is the difference between these two ways?

By default data is sent as JSON, when you add asFormParams data is sent as form params using the application/x-www-form-url-encoded content type.

https://github.com/kitetail/zttp/blob/master/src/Zttp.php#L61-L64

Oh! So, what is the difference between these two ways? They also returned different results.

Zttp::post('http://example.com', [
           'foo' => 'bar'
   ];
Zttp::post('http://example.com?foo=boo');

One is sending a JSON post body and the other is just sending query string parameters. The difference in response is up to the server you are talking to because the requests are different.

Closing as not an actual issue, just a question 👍