{"id":1214,"date":"2024-07-31T13:25:19","date_gmt":"2024-07-31T04:25:19","guid":{"rendered":"https:\/\/shinke1987.net\/?p=1214"},"modified":"2024-07-31T13:25:20","modified_gmt":"2024-07-31T04:25:20","slug":"php%e3%81%a7curl%e9%96%a2%e6%95%b0%e3%82%92%e5%88%a9%e7%94%a8%e3%81%97%e3%81%a6json%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b%e4%be%8b","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=1214","title":{"rendered":"PHP\u3067cURL\u95a2\u6570\u3092\u5229\u7528\u3057\u3066JSON\u53d6\u5f97\u3059\u308b\u4f8b"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u524d\u63d0<\/h2>\n\n\n\n<p>\u697d\u5929\u30a6\u30a7\u30d6\u30b5\u30fc\u30d3\u30b9\u306eAPI\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001<br>\u697d\u5929\u5e02\u5834\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u5229\u7528\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3ID\u7b49\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">cURL\u95a2\u6570\u3092\u5229\u7528\u3059\u308b\u8981\u4ef6<\/h2>\n\n\n\n<h3 id=\"toc2\" class=\"wp-block-heading\">PHP 8.0.0 \u4ee5\u964d\u306e\u5834\u5408<\/h3>\n\n\n\n<p>libcurl\u30d1\u30c3\u30b1\u30fc\u30b8\u306e7.29.0\u4ee5\u964d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u5fc5\u8981\u3002<\/p>\n\n\n\n<h3 id=\"toc3\" class=\"wp-block-heading\">\u78ba\u8a8d\u624b\u9806<\/h3>\n\n\n\n<p>Linux\u3084Mac\u74b0\u5883\u306a\u3089\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ php -i | grep cURL\n<\/pre><\/div>\n\n\n<p>\u8868\u793a\u3055\u308c\u305f\u7d50\u679c\u304c\u6b21\u306e\u5f62\u3067\u3042\u308c\u3070\u4f7f\u7528\u53ef\u80fd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>cURL support => enabled<\/li>\n\n\n\n<li>cURL Information => 7.29.0\u4ee5\u4e0a\u306e\u30d0\u30fc\u30b8\u30e7\u30f3<\/li>\n<\/ul>\n\n\n\n<p>\u5ff5\u306e\u305f\u3081https\u304c\u4f7f\u3048\u308b\u3053\u3068\u3082\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ php -i | grep Protocols | grep https\n$ php -i | grep &#039;SSL =&gt;&#039;\n<\/pre><\/div>\n\n\n<p>\u8868\u793a\u3055\u308c\u305f\u7d50\u679c\u304c\u4e0b\u8a18\u306e\u3088\u3046\u3067\u3042\u308c\u3070\u4f7f\u7528\u53ef\u80fd\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nProtocols =&gt; dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSSL =&gt; Yes\n<\/pre><\/div>\n\n\n<h2 id=\"toc4\" class=\"wp-block-heading\">\u53c2\u8003\u8cc7\u6599<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.php.net\/manual\/ja\/curl.examples-basic.php\">PHP: \u57fa\u672c\u7684\u306a curl \u306e\u4f7f\u7528\u6cd5 &#8211; Manual<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webservice.rakuten.co.jp\/\">Rakuten Web Service<\/a><\/li>\n<\/ul>\n\n\n\n<h2 id=\"toc5\" class=\"wp-block-heading\">JSON\u30c7\u30fc\u30bf\u53d6\u5f97\u7528URL\u3092\u78ba\u8a8d<\/h2>\n\n\n\n<p>\u697d\u5929\u30a6\u30a7\u30d6\u30b5\u30fc\u30d3\u30b9\u306eAPI Test Form \u306b\u3066\u4f55\u3089\u304b\u306eJSON\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3001\u305d\u306e\u969b\u306eURL\u3092\u63a7\u3048\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<h2 id=\"toc6\" class=\"wp-block-heading\">\u30b3\u30fc\u30c9<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n$url = &#039;https:\/\/app.rakuten.co.jp\/services\/api\/\u3067\u59cb\u307e\u308b\u3001JSON\u30c7\u30fc\u30bf\u53d6\u5f97\u7528URL&#039;;\n\/\/ \u4e0b\u8a18\u306efile_get_contents\u95a2\u6570\u3067\u3082\u53d6\u5f97\u3067\u304d\u308b\u3002\n\/\/$result = file_get_contents($url);\n\/\/var_dump($result);\n\n$cUrlHandler = curl_init($url);\n\n\/\/ HTTP\u30ec\u30b9\u30dd\u30f3\u30b9\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3067400\u4ee5\u4e0a\u304c\u8fd4\u3063\u3066\u304d\u305f\u3089\u30a8\u30e9\u30fc\u3068\u3059\u308b\u3002\ncurl_setopt($cUrlHandler,CURLOPT_FAILONERROR, true);\n\n\/\/ cURL\u95a2\u6570\u306e\u5b9f\u884c\u306b\u304b\u3051\u3089\u308c\u308b\u6642\u9593\u309230\u79d2\u306b\u8a2d\u5b9a\u3002\ncurl_setopt($cUrlHandler,CURLOPT_TIMEOUT, 30);\n\n\/\/ HTTPS\u30d7\u30ed\u30c8\u30b3\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u8a2d\u5b9a\u3002\ncurl_setopt($cUrlHandler, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);\n\n\/\/ \u6210\u529f\u3057\u305f\u5834\u5408\u3001\u53d6\u5f97\u7d50\u679c\u3092\u8fd4\u3059\u3088\u3046\u8a2d\u5b9a\u3002\ncurl_setopt($cUrlHandler, CURLOPT_RETURNTRANSFER, true);\n\n$result = curl_exec($cUrlHandler);\n\nif ($result === false) {\n    echo curl_error($cUrlHandler);\n}\n\ncurl_close($cUrlHandler);\n\nvar_dump($result);\n<\/pre><\/div>\n\n\n<h2 id=\"toc7\" class=\"wp-block-heading\">\u7d50\u679c\u78ba\u8a8d<\/h2>\n\n\n\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u6210\u529f\u3059\u308c\u3070JSON\u30c7\u30fc\u30bf\u304c\u8868\u793a\u3055\u308c\u308b\u3002<br>\u5931\u6557\u3059\u308b\u3068\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u63d0 \u697d\u5929\u30a6\u30a7\u30d6\u30b5\u30fc\u30d3\u30b9\u306eAPI\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001\u697d\u5929\u5e02\u5834\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u5229\u7528\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3ID\u7b49\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002 cURL\u95a2\u6570\u3092\u5229\u7528\u3059\u308b\u8981\u4ef6 PHP 8.0.0 \u4ee5\u964d\u306e\u5834\u5408 libcurl\u30d1\u30c3\u30b1\u30fc [&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":[81],"class_list":["post-1214","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1214","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=1214"}],"version-history":[{"count":1,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1214\/revisions"}],"predecessor-version":[{"id":1215,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1214\/revisions\/1215"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}