{"id":354,"date":"2023-11-23T14:27:09","date_gmt":"2023-11-23T06:27:09","guid":{"rendered":"https:\/\/blog.quantoyo.com\/?p=354"},"modified":"2025-04-08T11:47:53","modified_gmt":"2025-04-08T03:47:53","slug":"linux-curl-%e6%8c%87%e4%bb%a4-%e8%88%87%e5%82%b3%e9%80%81json%e6%a0%bc%e5%bc%8f%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/blog.quantoyo.com\/?p=354","title":{"rendered":"Linux curl \u6307\u4ee4 \u8207\u50b3\u9001json\u683c\u5f0f\u8cc7\u6599"},"content":{"rendered":"\n<p>curl \u53ef\u4ee5\u958b\u555f\u9032\u968e\u529f\u80fd\uff0c\u4f86\u52a0\u4e0a\u66f4\u591a\u7684\u53c3\u6578<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>curl \u57fa\u672c\u683c\u5f0f\u70ba<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>curl &#91;options...] &lt;url>\n\n\u4e2d\u9593\u70ba\u53c3\u6578\uff0c\u6700\u5f8c\u662f\u7db2\u5740\nex. curl https:\/\/blog.quantoyo.com\n\n\u53c3\u6578\u683c\u5f0f\u5982\u4e0b\n-X\/--request        \/\/\u5e36\u5165GET|POST|PUT|DELETE|PATCH\uff0c\u9810\u8a2d\u70baGET\n-H\/--header         \/\/\u53ef\u591a\u6b21\u4f7f\u7528\uff0c\u4e26\u5e36\u5165\u4e0d\u540cheader\n-i\/--include        \n-d\/--data           \/\/\u901a\u5e38\u4f7f\u7528\u5728POST\u5e36\u8cc7\u6599\n-v\/--verbose        \/\/\u770b\u66f4\u591adebug\u8a0a\u606f\n-u\/--user           \n-b\/--cookie \n-k                  \/\/\u5ffd\u8996https \u7684\u6191\u8b49\u932f\u8aa4<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u8981\u4e0b\u8f09\u6a94\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>\u6709\u5169\u7a2e\u65b9\u5f0f\n1. \u4e0d\u6307\u5b9a\u6a94\u540d\uff0c\u7528\u7db2\u7ad9\u4e0a\u7684\u540d\u7a31\nex. curl -O https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2023\/11\/PANG4696.jpg\n\n2. \u6307\u5b9a\u6a94\u540d(\u5c0f\u5bebo)\nex. curl -o test.jpg https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2023\/11\/PANG4696.jpg<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u8981\u6a21\u64ecFORM \u8868\u55ae\u7684request<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>curl -X POST -H \"application\/x-www-form-urlencoded\" -d \"data=testdata&amp;user=quanto\"  https:\/\/test.quantoyo.com\/form.php\n\n\u4f7f\u7528 POST \u65b9\u5f0f\uff0c\u4e26\u5e36\u5165\u5169\u7b46\u8cc7\u6599\uff0c\u4f7f\u7528\uff06\u9694\u958b\uff0c\u6700\u5f8c\u9762\u5247\u662f\u8981\u50b3\u5165\u7684url\n\n<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528curl POST \u50b3\u9001 json \u8cc7\u6599<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>curl -X POST -H \"Content-Type:application\/json\" -d '{\"request\":\"thisisrequest\",\"name\":\"quanto\"}' https:\/\/test.quantoyo.com\/json.php\n\n\u5c07\u6703\u4f7f\u7528 POST \u65b9\u5f0f\uff0c\u5c07Content-Type\u8a2d\u70baapplication\/json\uff0c\u4e26\u5e36\u5165\u8cc7\u6599json\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u53ef\u4ee5\u5c07\u8981\u50b3\u8f38\u7684\u5167\u5bb9\u5148\u653e\u5230\u6a94\u6848\u5167\uff0c\u518d\u50b3\u51fa\u53bb<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>echo '{\"request\":\"thisisrequest\",\"name\":\"quanto\"}' > send.json\n\ncurl -k \"https:\/\/123.123.123.123\/json.php\" -H \"Content-Type: application\/json\" -d @send.json -X POST\n\n\n\u9019\u7a2e\u65b9\u5f0f\u53ef\u4ee5\u9810\u5148\u7de8\u8f2f\u597d\u8981\u50b3\u8f38\u7684\u6a94\u6848\uff0c\u5c31\u4e0d\u7528\u6bcf\u6b21\u91cd\u65b0\u6253\n\u9019\u908a\u7528\u5230 curl -k \u662f\u53ef\u4ee5\u5ffd\u7565https \u7684\u53c3\u6578\uff0c\u9019\u53ef\u4ee5\u4f7f\u7528\u5728 \u7db2\u5740\u652f\u63f4443 port \u4f46\u662f\u56e0\u70ba\u662fip \u6216\u8005\u6191\u8b49\u4e26\u4e0d\u5408\u4e4e\u898f\u7bc4\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>curl \u53ef\u4ee5\u958b\u555f\u9032\u968e\u529f\u80fd\uff0c\u4f86\u52a0\u4e0a\u66f4\u591a\u7684\u53c3\u6578<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[49,51,37,50],"class_list":["post-354","post","type-post","status-publish","format-standard","hentry","category-technology","tag-curl","tag-json","tag-linux","tag-post"],"_links":{"self":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=354"}],"version-history":[{"count":5,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions"}],"predecessor-version":[{"id":2975,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions\/2975"}],"wp:attachment":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}