{"id":30461,"date":"2022-10-31T21:15:47","date_gmt":"2023-07-21T19:59:24","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/"},"modified":"2025-08-12T19:16:42","modified_gmt":"2025-08-12T11:16:42","slug":"php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/","title":{"rendered":"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f"},"content":{"rendered":"<p>\u6211\u5728Ubuntu 23.04\u4e0a\u8fdb\u884c\u4e86\u4e0e\u4e0b\u4e00\u9875\u76f8\u540c\u7684\u64cd\u4f5c\u3002<br \/>\n\u4f7f\u7528PHP\u7684Http\u5ba2\u6237\u7aef\u5e93Guzzle\u5305\u3002<\/p>\n<h2>\u5b89\u88c5\u56fe\u4e66\u9986<\/h2>\n<pre class=\"post-pre\"><code>composer require guzzlehttp\/guzzle\r\n<\/code><\/pre>\n<p>\u5df2\u521b\u5efa\u7684 composer.json<\/p>\n<pre class=\"post-pre\"><code><span class=\"p\">{<\/span>\r\n    <span class=\"nl\">\"require\"<\/span><span class=\"p\">:<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"nl\">\"guzzlehttp\/guzzle\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"^7.8\"<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<h2>\u6d4b\u8bd5\u7a0b\u5e8f<\/h2>\n<pre class=\"post-pre\"><code>#! \/usr\/bin\/php\r\n<span class=\"cp\">&lt;?php<\/span>\r\n\r\n<span class=\"k\">require<\/span> <span class=\"s1\">'vendor\/autoload.php'<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"kn\">use<\/span> <span class=\"nc\">GuzzleHttp\\Client<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"nv\">$client<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"nc\">Client<\/span><span class=\"p\">();<\/span>\r\n\r\n<span class=\"nv\">$response<\/span> <span class=\"o\">=<\/span> <span class=\"nv\">$client<\/span><span class=\"o\">-&gt;<\/span><span class=\"nf\">request<\/span><span class=\"p\">(<\/span><span class=\"s1\">'GET'<\/span><span class=\"p\">,<\/span> <span class=\"s1\">'https:\/\/jsonplaceholder.typicode.com\/posts\/1'<\/span><span class=\"p\">);<\/span>\r\n\r\n<span class=\"k\">echo<\/span> <span class=\"nv\">$response<\/span><span class=\"o\">-&gt;<\/span><span class=\"nf\">getBody<\/span><span class=\"p\">();<\/span>\r\n\r\n<span class=\"cp\">?&gt;<\/span>\r\n<\/code><\/pre>\n<p>\u6267\u884c\u7ed3\u679c<\/p>\n<pre class=\"post-pre\"><code>$ .\/check01.php \r\n{\r\n  \"userId\": 1,\r\n  \"id\": 1,\r\n  \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\r\n  \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\r\n<\/code><\/pre>\n<p>\u4f7f\u7528Httpie\u53d1\u51fa\u76f8\u540c\u7684\u8bf7\u6c42<\/p>\n<pre class=\"post-pre\"><code>$ http https:\/\/jsonplaceholder.typicode.com\/posts\/1\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Credentials: true\r\nAge: 5591\r\nCF-Cache-Status: HIT\r\nCF-RAY: 80b9bf0be94df583-NRT\r\nCache-Control: max-age=43200\r\nConnection: keep-alive\r\nContent-Encoding: gzip\r\nContent-Type: application\/json; charset=utf-8\r\nDate: Sun, 24 Sep 2023 08:44:34 GMT\r\nEtag: W\/\"124-yiKdLzqO5gfBrJFrcdJ8Yq0LGnU\"\r\nExpires: -1\r\nNEL: {\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}\r\nPragma: no-cache\r\nReport-To: {\"endpoints\":[{\"url\":\"https:\\\/\\\/a.nel.cloudflare.com\\\/report\\\/v3?s=q4EGse%2F7X%2FKbBpDTbGwWcY2%2B5dz%2Bn1cPOE7P31KLFzztbanJdUjgxHe8KIwVnkYQE%2FXFMCQzT54vUngzwkhrKBVcLAmw1txwShE4Ck23bDYTLiJGmRjUleDUOEzULFOkXRKq6tJAKec1PaSCWRB1Xqm2X%2FY2e4h8WsaR\"}],\"group\":\"cf-nel\",\"max_age\":604800}\r\nServer: cloudflare\r\nTransfer-Encoding: chunked\r\nVary: Origin, Accept-Encoding\r\nVia: 1.1 vegur\r\nX-Content-Type-Options: nosniff\r\nX-Powered-By: Express\r\nX-Ratelimit-Limit: 1000\r\nX-Ratelimit-Remaining: 999\r\nX-Ratelimit-Reset: 1691790101\r\nalt-svc: h3=\":443\"; ma=86400\r\n\r\n{\r\n    \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\",\r\n    \"id\": 1,\r\n    \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\r\n    \"userId\": 1\r\n}\r\n<\/code><\/pre>\n<h2>\u786e\u8ba4\u7684\u7248\u672c de<\/h2>\n<pre class=\"post-pre\"><code>$ php --version\r\nPHP 8.1.12-1ubuntu4.3 (cli) (built: Aug 17 2023 17:37:48) (NTS)\r\nCopyright (c) The PHP Group\r\nZend Engine v4.1.12, Copyright (c) Zend Technologies\r\n    with Zend OPcache v8.1.12-1ubuntu4.3, Copyright (c), by Zend Technologies\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5728Ubuntu 23.04\u4e0a\u8fdb\u884c\u4e86\u4e0e\u4e0b\u4e00\u9875\u76f8\u540c\u7684\u64cd\u4f5c\u3002 \u4f7f\u7528PHP\u7684Http\u5ba2\u6237\u7aef\u5e93Guzzle\u5305\u3002 \u5b89\u88c5\u56fe [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[227],"class_list":["post-30461","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-227"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u5173\u4e8ePHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/php\uff1a\u4f7f\u7528guzzlehttp-guzzle\u7684\u65b9\u5f0f\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\" \/>\n<meta property=\"og:description\" content=\"\u5173\u4e8ePHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/php\uff1a\u4f7f\u7528guzzlehttp-guzzle\u7684\u65b9\u5f0f\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-21T19:59:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-12T11:16:42+00:00\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/\",\"name\":\"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-07-21T19:59:24+00:00\",\"dateModified\":\"2025-08-12T11:16:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"description\":\"\u5173\u4e8ePHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\u7684\u6280\u672f\u6587\u7ae0\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f - Blog - Silicon Cloud","description":"\u5173\u4e8ePHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\u7684\u6280\u672f\u6587\u7ae0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/php\uff1a\u4f7f\u7528guzzlehttp-guzzle\u7684\u65b9\u5f0f\/","og_locale":"zh_CN","og_type":"article","og_title":"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f","og_description":"\u5173\u4e8ePHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\u7684\u6280\u672f\u6587\u7ae0","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/php\uff1a\u4f7f\u7528guzzlehttp-guzzle\u7684\u65b9\u5f0f\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-07-21T19:59:24+00:00","article_modified_time":"2025-08-12T11:16:42+00:00","author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/","name":"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-07-21T19:59:24+00:00","dateModified":"2025-08-12T11:16:42+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"description":"\u5173\u4e8ePHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f\u7684\u6280\u672f\u6587\u7ae0","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP\uff1a\u4f7f\u7528guzzlehttp\/guzzle\u7684\u65b9\u5f0f"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/php%ef%bc%9a%e4%bd%bf%e7%94%a8guzzlehttp-guzzle%e7%9a%84%e6%96%b9%e5%bc%8f\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/30461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=30461"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/30461\/revisions"}],"predecessor-version":[{"id":56875,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/30461\/revisions\/56875"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=30461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=30461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=30461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}