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

php uses guzzule 6 to send HTTP requests

WBOY
Release: 2016-07-29 08:58:54
Original
1907 people have browsed it

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>
Copy after login

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template