Home >Backend Development >PHP Tutorial >php uses guzzule 6 to send HTTP requests

php uses guzzule 6 to send HTTP requests

WBOY
WBOYOriginal
2016-07-29 08:58:541910browse

guzzle was upgraded to version 6 unknowingly. After the upgrade, the usage was different from the original 3.*. I was confused when I read the documentation. It took me a long time to find the usage from the documentation:
POST

<code><span>$response</span> = <span>$client</span>->request(<span>'POST'</span>, <span>'http://httpbin.org/post'</span>, [
    <span>'form_params'</span> => [
        <span>'field_name'</span> => <span>'abc'</span>,
        <span>'other_field'</span> => <span>'123'</span>,
        <span>'nested_field'</span> => [
            <span>'nested'</span> => <span>'hello'</span>
        ]
    ]
]);
<span>$result</span> = <span>$response</span>->getBody();</code>

GET

<code><span>$client</span><span>=</span><span>new</span> Client();
<span>$res</span><span>=</span><span>$client</span><span>-></span>request(<span>'GET'</span>, <span>$url</span><span>.</span><span>"?param1=1&param2=9"</span>);
<span>$result</span><span>=</span><span>$res</span><span>-></span>getBody();</code>

To be fair, it’s quite convenient.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces how to use guzzule 6 to send HTTP requests in PHP, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn