kitetail / zttp

A developer-experience focused HTTP client, optimized for most common use cases.
MIT License
1.68k stars 120 forks source link

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

Closed cornjosh closed 5 years ago

cornjosh commented 5 years ago

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?

adamwathan commented 5 years ago

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

cornjosh commented 5 years ago

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');
adamwathan commented 5 years ago

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 👍