{"id":48637,"date":"2024-12-02T08:36:20","date_gmt":"2024-12-02T00:36:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48637\/"},"modified":"2024-12-02T08:36:20","modified_gmt":"2024-12-02T00:36:20","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-curl_setopt-%e5%87%bd%e6%95%b0%e4%bb%8e%e7%bd%91%e7%bb%9c%e8%af%b7%e6%b1%82%e7%bb%93%e6%9e%9c%e4%b8%ad%e6%8f%90%e5%8f%96-count-%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48637\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/1730177316672069240616d.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>curl_setopt \u7684\u5de7\u7528\uff1a\u6b63\u5219\u63d0\u53d6\u8bf7\u6c42\u7ed3\u679c count<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 php \u7684 curl_setopt \u51fd\u6570\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u65f6\uff0c\u5f00\u53d1\u8005\u6709\u65f6\u9700\u8981\u4ece\u54cd\u5e94\u7ed3\u679c\u4e2d\u63d0\u53d6\u7279\u5b9a\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u8981\u63d0\u53d6 url \u54cd\u5e94\u4e2d count \u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u548c trim \u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>function postAction() {\n\n    \/\/ \u8bf7\u6c42 URL\uff08\u5c06\u53c2\u6570\u5168\u90e8\u79fb\u9664\uff09\n    $url = \"https:\/\/mall.cnki.net\/mallsearch\/SearchSer\/Do\";\n    \/\/ \u53c2\u6570\u6570\u7ec4\n    $parameters = array(\n        'keys' =&gt; 'Roy',\n\/\/        'password' =&gt; '654321'\n    );\n\n    \/\/ \u521d\u59cb\u5316 curl\n    $ch = curl_init();\n\n    \/\/ \u8bbe\u7f6e\u53d8\u91cf\n    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\n    curl_setopt($ch, CURLOPT_URL, $url);\n    curl_setopt($ch, CURLOPT_POST, 1);\n    curl_setopt($ch, CURLOPT_HEADER, 0);\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n    curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);\n\n    \/\/ \u6267\u884c\u8bf7\u6c42\n    $return = curl_exec($ch);\n\n    \/\/ \u5173\u95ed curl\n    curl_close($ch);\n\n    \/\/ \u79fb\u9664 url \u53c2\u6570\n    $return = trim($return, '()');\n\n    \/\/ \u89e3\u6790 JSON\n    $result = json_decode($return, true);\n\n    \/\/ \u8f93\u51fa count\n    echo $result['count'];\n}\n\npostAction();<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53bb\u6389 url \u53c2\u6570\uff0c\u518d\u5c06\u62ec\u53f7\u5185\u7684\u5185\u5bb9\u53bb\u9664\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u7eaf\u51c0\u7684 json \u5185\u5bb9\u3002\u63a5\u4e0b\u6765\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7 json_decode \u51fd\u6570\u5c06 json \u5b57\u7b26\u4e32\u89e3\u6790\u6210\u6570\u7ec4\uff0c\u4ece\u800c\u83b7\u53d6 count \u7684\u503c\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f \u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u5982\u4f55\u4f7f\u7528 curl_setopt \u51fd\u6570\u4ece\u7f51\u7edc\u8bf7\u6c42\u7ed3\u679c\u4e2d\u63d0\u53d6 count \u503c\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002 curl_setopt \u7684\u5de7\u7528\uff1a\u6b63\u5219\u63d0\u53d6\u8bf7\u6c42\u7ed3\u679c count \u5728\u4f7f\u7528 php \u7684 curl_setopt \u51fd\u6570\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u65f6\uff0c\u5f00\u53d1\u8005\u6709\u65f6\u9700\u8981\u4ece\u54cd\u5e94\u7ed3\u679c\u4e2d\u63d0\u53d6\u7279\u5b9a\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u8981\u63d0\u53d6 url \u54cd\u5e94\u4e2d count \u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u548c trim \u51fd\u6570\u6765\u5b9e\u73b0\u3002 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u4ee3\u7801\u793a\u4f8b\uff1a function postAction() { \/\/ \u8bf7\u6c42 URL\uff08\u5c06\u53c2\u6570\u5168\u90e8\u79fb\u9664\uff09 $url = &#8220;https:\/\/mall.cnki.net\/mallsearch\/SearchSer\/Do&#8221;; \/\/ \u53c2\u6570\u6570\u7ec4 $parameters = array( &#8216;keys&#8217; =&gt; &#8216;Roy&#8217;, \/\/ &#8216;password&#8217; =&gt; &#8216;654321&#8217; ); \/\/ \u521d\u59cb\u5316 curl $ch = curl_init(); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48637","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48637"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48637\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}