{"id":904,"date":"2023-05-24T10:57:31","date_gmt":"2023-05-24T01:57:31","guid":{"rendered":"https:\/\/shinke1987.net\/?p=904"},"modified":"2023-05-24T10:57:32","modified_gmt":"2023-05-24T01:57:32","slug":"http%e3%82%af%e3%83%a9%e3%82%a4%e3%82%a2%e3%83%b3%e3%83%88guzzle%e3%82%92%e3%82%bb%e3%83%83%e3%83%88%e3%82%a2%e3%83%83%e3%83%97%e3%81%a8%e7%b0%a1%e6%98%93%e5%8b%95%e4%bd%9c%e7%a2%ba%e8%aa%8d","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=904","title":{"rendered":"HTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8Guzzle\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3068\u7c21\u6613\u52d5\u4f5c\u78ba\u8a8d"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h2>\n\n\n\n<p>\u6700\u65b0\u306eGuzzle\u3092\u8a2d\u7f6e\u3059\u308b\u305f\u3081\u306b\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u30a2\u30d7\u30ea\u30eb\u30fc\u30c8\u3067\u5b9f\u884c\u3059\u308b\u3068\u3001<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&gt; composer require guzzlehttp\/guzzle *\n<\/pre><\/div>\n\n\n<p>\u6b21\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nInfo from https:\/\/repo.packagist.org: #StandWithUkraine\n.\/composer.json has been created\nRunning composer update guzzlehttp\/guzzle\nLoading composer repositories with package information\nUpdating dependencies\nLock file operations: 8 installs, 0 updates, 0 removals\n  - Locking guzzlehttp\/guzzle (7.7.0)\n  - Locking guzzlehttp\/promises (2.0.0)\n  - Locking guzzlehttp\/psr7 (2.5.0)\n  - Locking psr\/http-client (1.0.2)\n  - Locking psr\/http-factory (1.0.2)\n  - Locking psr\/http-message (2.0)\n  - Locking ralouphie\/getallheaders (3.0.3)\n  - Locking symfony\/deprecation-contracts (v3.2.1)\nWriting lock file\nInstalling dependencies from lock file (including require-dev)\nPackage operations: 8 installs, 0 updates, 0 removals\n    Failed to download symfony\/deprecation-contracts from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing symfony\/deprecation-contracts (v3.2.1) into cache\n    Failed to download psr\/http-message from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing psr\/http-message (2.0) into cache\n    Failed to download psr\/http-client from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing psr\/http-client (1.0.2) into cache\n    Failed to download ralouphie\/getallheaders from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing ralouphie\/getallheaders (3.0.3) into cache\n    Failed to download psr\/http-factory from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing psr\/http-factory (1.0.2) into cache\n    Failed to download guzzlehttp\/psr7 from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing guzzlehttp\/psr7 (2.5.0) into cache\n    Failed to download guzzlehttp\/promises from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing guzzlehttp\/promises (2.0.0) into cache\n    Failed to download guzzlehttp\/guzzle from dist: The zip extension and unzip\/7z commands are both missing, skipping.\nThe php.ini used by your command-line PHP is: C:\\xampp\\php\\php.ini\n    Now trying to download from source\n  - Syncing guzzlehttp\/guzzle (7.7.0) into cache\n  - Installing symfony\/deprecation-contracts (v3.2.1): Cloning e2d1534420 from cache\n  - Installing psr\/http-message (2.0): Cloning 402d35bcb9 from cache\n  - Installing psr\/http-client (1.0.2): Cloning 0955afe482 from cache\n  - Installing ralouphie\/getallheaders (3.0.3): Cloning 120b605dfe from cache\n  - Installing psr\/http-factory (1.0.2): Cloning e616d01114 from cache\n  - Installing guzzlehttp\/psr7 (2.5.0): Cloning b635f279ed from cache\n  - Installing guzzlehttp\/promises (2.0.0): Cloning 3a494dc7dc from cache\n  - Installing guzzlehttp\/guzzle (7.7.0): Cloning fb7566cacc from cache\n3 package suggestions were added by new dependencies, use `composer suggest` to see details.\nGenerating autoload files\n4 packages you are using are looking for funding.\nUse the `composer fund` command to find out more!\nNo security vulnerability advisories found\n<\/pre><\/div>\n\n\n<p>composer\u3092\u5b9f\u884c\u3057\u305f\u30d5\u30a9\u30eb\u30c0\uff08\u30a2\u30d7\u30ea\u30eb\u30fc\u30c8\uff09\u306b\u4f5c\u6210\u3055\u308c\u308bcomposer.json\u3092\u958b\u304d\u3001<br>\u6b21\u306e\u3088\u3046\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n    &quot;require&quot;: {\n        &quot;guzzlehttp\/guzzle&quot;: &quot;*&quot;\n    }\n}\n<\/pre><\/div>\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">\u52d5\u4f5c\u78ba\u8a8d\uff08\u53c2\u8003\u66f8\uff1a\u72ec\u7fd2PHP\u306e\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30c8\u3092\u5229\u7528\uff09<\/h2>\n\n\n\n<p>\u4e0b\u8a18\u30b3\u30fc\u30c9\u3092\u8a2d\u7f6e\u3057\u3001<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nrequire_once &#039;.\/vendor\/autoload.php&#039;;\n\n\/\/ \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u751f\u6210\n$cli = new GuzzleHttp\\Client(&#x5B;\n    &#039;base_uri&#039; =&gt; &#039;https:\/\/wings.msn.to\/&#039;\n]);\n\n\/\/ \u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\n$res = $cli -&gt; request(&#039;get&#039;, &#039;\/tmp\/sample.txt&#039;);\n\n\/\/ \u53d6\u5f97\u3057\u305f\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u51fa\u529b\nprint (&quot;&lt;b&gt;getBody()\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306e\u8868\u793a&lt;br&gt;&lt;\/b&gt;&quot;);\nprint ($res -&gt; getBody() . &#039;&lt;br&gt;&lt;br&gt;&#039;);\n\n\/\/ json\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092request\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u3066\u51fa\u529b\n$res = $cli -&gt; request(&#039;get&#039;, &#039;\/tmp\/books.json&#039;);\n$obj = json_decode($res -&gt; getBody());\nprint (&quot;&lt;b&gt;request()\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306e\u8868\u793a&lt;br&gt;&lt;\/b&gt;&quot;);\nprint_r ($obj);\nprint (&#039;&lt;br&gt;&lt;br&gt;&#039;);\n\n\/\/ json\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092get\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u3066\u51fa\u529b\n$res = $cli -&gt; get(&#039;\/tmp\/books.json&#039;);\n$obj = json_decode($res -&gt; getBody());\nprint (&quot;&lt;b&gt;get()\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306e\u8868\u793a&lt;br&gt;&lt;\/b&gt;&quot;);\nprint_r($obj);\nprint (&#039;&lt;br&gt;&lt;br&gt;&#039;);\n\n\/\/ json\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u683c\u7d0d\u3057\u305f\u5909\u6570\u306evar_dump\nprint (&quot;&lt;b&gt;var_dump()\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306e\u8868\u793a&lt;br&gt;&lt;\/b&gt;&quot;);\nvar_dump($obj);\nprint(&#039;&lt;br&gt;&lt;br&gt;&#039;);\n\n\/\/ json\u30d5\u30a1\u30a4\u30eb\u5185\u306e\u7279\u5b9a\u306e\u8981\u7d20\u3092\u53d6\u5f97\nprint (&#039;&lt;b&gt;$obj -&gt; books&#x5B;0] -&gt; title&lt;br&gt;&lt;\/b&gt;&#039;);\nprint ($obj -&gt; books&#x5B;0] -&gt; {&#039;title&#039;});\nprint (&#039;&lt;br&gt;&lt;br&gt;&#039;);\n\n\/\/ POST\u3092\u884c\u3044\u3001\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3002\n$res = $cli -&gt; post(&#039;\/tmp\/post.php&#039;, &#x5B;\n    &#039;form_params&#039; =&gt; &#x5B;\n        &#039;name&#039; =&gt; &#039;\u30c6\u30b9\u30c8\u30cd\u30fc\u30e0&#039;\n    ]\n]);\nprint (&#039;&lt;b&gt;POST\u3067name\u306b\u30c6\u30b9\u30c8\u30cd\u30fc\u30e0\u3092\u9001\u4fe1\u3057\u3001\u7d50\u679c\u3092\u8868\u793a\u3059\u308b&lt;br&gt;&lt;\/b&gt;&#039;);\nprint ($res -&gt; getBody());\n<\/pre><\/div>\n\n\n<p>Web\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u6b21\u306e\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"974\" src=\"https:\/\/shinke1987.net\/wp-content\/uploads\/2023\/05\/2023-05-24-10.49.42-localhost-9bae5966b9fb-1024x974.png\" alt=\"\" class=\"wp-image-905\" srcset=\"https:\/\/shinke1987.net\/wp-content\/uploads\/2023\/05\/2023-05-24-10.49.42-localhost-9bae5966b9fb-1024x974.png 1024w, https:\/\/shinke1987.net\/wp-content\/uploads\/2023\/05\/2023-05-24-10.49.42-localhost-9bae5966b9fb-300x285.png 300w, https:\/\/shinke1987.net\/wp-content\/uploads\/2023\/05\/2023-05-24-10.49.42-localhost-9bae5966b9fb-768x730.png 768w, https:\/\/shinke1987.net\/wp-content\/uploads\/2023\/05\/2023-05-24-10.49.42-localhost-9bae5966b9fb-1536x1461.png 1536w, https:\/\/shinke1987.net\/wp-content\/uploads\/2023\/05\/2023-05-24-10.49.42-localhost-9bae5966b9fb.png 1901w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7 \u6700\u65b0\u306eGuzzle\u3092\u8a2d\u7f6e\u3059\u308b\u305f\u3081\u306b\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u30a2\u30d7\u30ea\u30eb\u30fc\u30c8\u3067\u5b9f\u884c\u3059\u308b\u3068\u3001 \u6b21\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u3002 composer\u3092\u5b9f\u884c\u3057\u305f\u30d5\u30a9\u30eb\u30c0\uff08\u30a2\u30d7\u30ea\u30eb\u30fc\u30c8\uff09\u306b\u4f5c\u6210\u3055\u308c\u308bcomposer.json\u3092\u958b\u304d\u3001\u6b21\u306e\u3088\u3046\u306b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80],"tags":[91,92,81],"class_list":["post-904","post","type-post","status-publish","format-standard","hentry","category-php","tag-composer","tag-guzzle","tag-php"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=904"}],"version-history":[{"count":1,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/904\/revisions"}],"predecessor-version":[{"id":906,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/904\/revisions\/906"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}