﻿{"id":773,"date":"2012-04-15T00:34:02","date_gmt":"2012-04-14T16:34:02","guid":{"rendered":"http:\/\/nick.workao.org\/?p=773"},"modified":"2012-04-23T00:22:29","modified_gmt":"2012-04-22T16:22:29","slug":"pycurl","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/773","title":{"rendered":"pycurl"},"content":{"rendered":"<p><a href=\"http:\/\/pycurl.sourceforge.net\/download\/\">http:\/\/pycurl.sourceforge.net\/download\/<\/a><\/p>\n<p><a href=\"http:\/\/pycurl.sourceforge.net\/doc\/curlobject.html\">http:\/\/pycurl.sourceforge.net\/doc\/curlobject.html<\/a><\/p>\n<p>wget <a href=\"http:\/\/nick.txtcc.com\/nickfiles\/curl-7.25.0.tar.gz\">http:\/\/nick.txtcc.com\/nickfiles\/curl-7.25.0.tar.gz<\/a>\nwget <a href=\"http:\/\/nick.txtcc.com\/nickfiles\/pycurl-7.19.0.tar.gz\">http:\/\/nick.txtcc.com\/nickfiles\/pycurl-7.19.0.tar.gz<\/a><\/p>\n<p>\u7f16\u8bd1\u5b89\u88c5\u4ee5\u4e0a\u4e24\u4e2a\u5373\u53ef\u3002<\/p>\n<p>ldconfig<\/p>\n<p>Python<\/p>\n<div id=\"highlighter_777144\">\n<div>\n<div>\n<pre lang=\"python\" line=\"1\">import pycurl\nc = pycurl.Curl()\nc.setopt(pycurl.URL, \"http:\/\/google.com\/\")\nc.setopt(pycurl.HTTPHEADER, [\"Accept:\"])\nimport StringIO\nb = StringIO.StringIO()\nc.setopt(pycurl.WRITEFUNCTION, b.write)\nc.setopt(pycurl.FOLLOWLOCATION, 1)\nc.setopt(pycurl.MAXREDIRS, 5)\nc.perform()\nprint b.getvalue()\nprint c.getinfo(pycurl.INFO_FILETIME)<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<h3>curl_easy_setopt<\/h3>\n<pre>\u544a\u8bc9 libcurl \u7684\u5982\u4f55\u505a\u4e8b\n<strong>CURLOPT_WRITEFUNCTION<\/strong>: \u5199(\u4e0b\u8f7d)\u56de\u4f20\u51fd\u6570,\u4f20\u9012\u4e00\u4e2a\u5199\u6307\u9488\u4f9b\u5916\u90e8\u64cd\u4f5c, \u4e00\u6b21\u56de\u8c03\u5185\u5bb9\u5927\u5c0f\u5728 CURL_MAX_WRITE_SIZE (curl.h\u5934\u6587\u4ef6)\u4e2d\u8bbe\u7f6e\n<strong>CURLOPT_WRITEDATA<\/strong>: \u76f4\u63a5\u5199\u6587\u4ef6,\u6307\u5b9a\u4e00\u4e2a\u6587\u4ef6\u540d\u5982c.setopt(pycurl.WRITEDATA, 'E:\\WebSite\\py\\1.txt') \u6ce8win\u4e0b\u4e0d\u80fd\u7528\n<strong>CURLOPT_READFUNCTION<\/strong>: \u8bfb(\u4e0a\u4f20)\u56de\u4f20\u51fd\u6570\n<strong>CURLOPT_SEEKFUNCTION<\/strong>: \u6570\u636e\u6307\u9488\u79fb\u52a8,int function(void *instream, curl_off_t offset, int origin);SEEK_SET, SEEK_CUR and SEEK_END,\u8fd4\u56deCURL_SEEKFUNC_OK\u6216CURL_SEEKFUNC_FAIL\u6216CURL_SEEKFUNC_CANTSEEK (0,1,2)\n<strong>CURLOPT_OPENSOCKETFUNCTION<\/strong>:\n<strong>CURLOPT_HEADERFUNCTION<\/strong>:\u53ea\u63a5\u6536\u5934\u6570\u636e size_t function( void *ptr, size_t size, size_t nmemb, void *userdata);\n<strong>CURLOPT_DEBUGFUNCTION<\/strong>: int curl_debug_callback (CURL *, curl_infotype, char *, size_t, void *);\n<strong>CURLOPT_VERBOSE<\/strong>: \u53c2\u6570\u8bbe\u7f6e\u4e3a1 \u80fd\u663e\u793a\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\n<strong>CURLOPT_HEADER<\/strong>: \u8bbe\u4e3a 1 \u5c06\u5728\u8fd4\u56de\u7684\u6587\u672c\u4e2d\u5305\u542b\u5934\u4fe1\u606f\n<strong>CURLOPT_NOSIGNAL<\/strong>: \u4e0d\u8d85\u65f6\n<strong>CURLOPT_FOLLOWLOCATION<\/strong>:\u8bbe\u7f6e\u4e3a1\u544a\u8bc9libcurl\u9075\u5faa\u4efb\u4f55\u8bbf\u95ee\n<strong>CURLOPT_MAXREDIRS<\/strong>: \u8bbe\u5b9a\u91cd\u5b9a\u5411\u7684\u6570\u76ee\u9650\u5236,\u8bbe\u7f6e\u4e3a-1\u8868\u793a\u65e0\u9650\u7684\u91cd\u5b9a\u5411\uff08\u9ed8\u8ba4\uff09\n<strong>CURLOPT_PUT<\/strong>:\u6570\u636e\u4e0a\u8f7d\u76f8\u5173\n<strong>CURLOPT_POST<\/strong>:\n<strong>CURLOPT_POSTREDIR<\/strong>:\n<strong>CURLOPT_POSTFIELDS<\/strong>:\n<strong>CURLOPT_POSTFIELDSIZE<\/strong>:\n<strong>CURLOPT_POSTFIELDSIZE_LARGE<\/strong>:\n<strong>CURLOPT_COPYPOSTFIELDS<\/strong>:\n<strong>CURLOPT_HTTPPOST<\/strong>:\n<strong>CURLOPT_UPLOAD<\/strong>:\n<strong>CURLOPT_AUTOREFERER<\/strong>:libcurl\u81ea\u52a8\u8bbe\u7f6eReferer\n<strong>CURLOPT_REFERER<\/strong>: \u4f2a\u9020\u6765\u6e90\u8def\u5f84\n<strong>CURLOPT_USERAGENT<\/strong>:\u81ea\u5b9a\u4e49USERAGENT\n<strong>CURLOPT_HTTPHEADER<\/strong>:\u81ea\u5b9a\u4e49\u5934\n<strong>CURLOPT_COOKIE<\/strong>: \"name1=content1; name2=content2;\"\n<strong>CURLOPT_COOKIEFILE<\/strong>:\n<strong>CURLOPT_COOKIEJAR<\/strong>:\n<strong>CURLOPT_COOKIESESSION<\/strong>: \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0clibcurl\u59cb\u7ec8\u52a0\u8f7d\u548c\u5b58\u50a8\u6240\u6709Cookie\n<strong>CURLOPT_COOKIELIST<\/strong>\n<strong>CURLOPT_HTTPGET<\/strong>\n<strong>CURLOPT_HTTP_VERSION<\/strong>: CURL_HTTP_VERSION_NONE,CURL_HTTP_VERSION_1_0,CURL_HTTP_VERSION_1_1\n<strong>CURLOPT_IGNORE_CONTENT_LENGTH<\/strong>:\u5ffd\u7565\u5185\u5bb9\u957f\u5ea6\u5934,\u9488\u5bf9\u7c7b\u4f3cApache 1.x\u7684\u670d\u52a1\u5668\n<strong>CURLOPT_HTTP_TRANSFER_DECODING<\/strong>:\u544a\u8bc9libcurl\u5982\u4f55\u5bf9\u4f20\u8f93\u89e3\u7801,(0,=1)\n<strong>CURLOPT_HTTP200ALIASES<\/strong>:\u81ea\u5b9a\u4e49HTTP 200\u54cd\u5e94\u522b\u540d,\u6709\u4e9b\u670d\u52a1\u5668\u5bf9200\u8fd4\u56de\u4e0d\u662f\u6807\u51c6\u7684\n<strong>CURLOPT_ENCODING<\/strong>:\u8bbe\u7f6e\u63a5\u6536\u7684\u5185\u5bb9\u7f16\u7801,\u540c Accept-Encoding, ('','gzip',....)\n<strong>CURLOPT_UNRESTRICTED_AUTH<\/strong>:\u6570\u8bbe\u7f6e\u4e3a1,\u7ee7\u7eed\u53d1\u9001\u8ba4\u8bc1\uff08\u7528\u6237+\u5bc6\u7801\uff09\nNETWORK OPTIONS\n<strong>CURLOPT_URL<\/strong>: http:\/\/xxxx,ftp:\/\/xxxx\n<strong>CURLOPT_PROXY<\/strong>:HTTP\u4ee3\u7406,\u4e3b\u673a\u540d\u6216IP\u5730\u5740\n<strong>CURLOPT_PROXYPORT<\/strong>:\u4ee3\u7406\u7aef\u53e3,\u4e5f\u53ef\u5728PROXY\u7684\u5730\u5740\u540e\u52a0\":\u7aef\u53e3\",\u5982 :8080\n<strong>CURLOPT_PROXYTYPE<\/strong>:\u4ee3\u7406\u7c7b\u578b,CURLPROXY_HTTP(\u9ed8\u8ba4), CURLPROXY_HTTP_1_0,CURLPROXY_SOCKS4,CURLPROXY_SOCKS5,CURLPROXY_SOCKS4A,CURLPROXY_SOCKS5_HOSTNAME,\n<strong>CURLOPT_NOPROXY<\/strong>:\u4e0d\u4f7f\u7528\u4ee3\u7406\u7684\u57df\n<strong>CURLOPT_HTTPPROXYTUNNEL<\/strong>:\n<strong>CURLOPT_BUFFERSIZE<\/strong>: libcurl\u7684\u7f13\u51b2\u533a\u5927\u5c0f\uff08\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\n\uff08\u8ba4\u8bc1\uff09\n<strong>CURLOPT_NETRC<\/strong>: \u6b64\u53c2\u6570\u63a7\u5236\u4f60\u7684\u5bc6\u7801,CURL_NETRC_OPTIONAL\u4f7f\u7528 ~\/.netrc \u6587\u4ef6, CURL_NETRC_IGNORED(\u9ed8\u8ba4):\u5ffd\u7565\u6587\u4ef6,CURL_NETRC_REQUIRED:\u544a\u8bc9\u8be5\u6587\u4ef6\u7684\u4f7f\u7528\u6240\u9700\u7684\u5e93\uff0c\u8981\u5ffd\u7565\u7684URL\u4fe1\u606f\n<strong>CURLOPT_NETRC_FILE<\/strong>: \u6307\u5b9a ~\/.netrc \u6587\u4ef6\n<strong>CURLOPT_USERNAME<\/strong>:\n<strong>CURLOPT_USERPWD<\/strong>:\n<strong>CURLOPT_PASSWORD<\/strong>:\n<strong>CURLOPT_PROXYUSERNAME<\/strong>:\n<strong>CURLOPT_PROXYUSERPWD<\/strong>:\n<strong>CURLOPT_HTTPAUTH<\/strong>:\n<strong>CURLOPT_PROXYAUTH<\/strong>:<\/pre>\n<ul>\n    <li>CURLAUTH_BASIC: HTTP\u57fa\u672c\u9a8c\u8bc1<\/li>\n    <li>CURLAUTH_DIGEST: HTTP\u6458\u8981\u8eab\u4efd\u9a8c\u8bc1<\/li>\n    <li>CURLAUTH_DIGEST_IE:<\/li>\n    <li>CURLAUTH_GSSNEGOTIATE: Kerberos5\u8ba4\u8bc1 \u8981\u5efa\u7acbGSS &#8211; API<\/li>\n    <li>CURLAUTH_NTLM: NTLM\u8eab\u4efd\u9a8c\u8bc1<\/li>\n    <li>CURLAUTH_ANY: \u8bbe\u7f6e\u6240\u6709\u9009\u9879,ibcurl\u81ea\u52a8\u9009\u62e9\u4e00\u4e2a\u5b83\u8ba4\u4e3a\u5408\u9002\u7684,\u5b89\u5168\u7684\u9a8c\u8bc1<<\/li>\n    <li>CURLAUTH_ANYSAFE: \u8bbe\u7f6e\u57fa\u672c\u9009\u9879&#8230;.<\/li>\n    <li>CURLAUTH_ONLY: \u5f3a\u5236\u6240\u6709\u8bf7\u6c42\u4f7f\u7528\u9a8c\u8bc1<\/li>\n<\/ul>\n<h3>getinfo<\/h3>\n<pre><strong>CURLINFO_RESPONSE_CODE<\/strong>: \u83b7\u5f97\u6700\u540e\u6536\u5230\u7684HTTP\u6216FTP\u7684\u4ee3\u7801,\u5982200,404,403,505 \u4ee3\u7406\u7684CONNECT\u54cd\u5e94\u8981\u53c2\u8003 CURLINFO_HTTP_CONNECTCODE\n<strong>CURLINFO_EFFECTIVE_URL<\/strong>: \u6700\u540e\u4e00\u6b21\u4f7f\u7528\u6709\u6548\u7684URL\n<strong>CURLINFO_HTTP_CONNECTCODE<\/strong> : \u957f\u671f\u63a5\u53d7\u6700\u540e\u6536\u5230\u7684\u4ee3\u7406\u54cd\u5e94\u4ee3\u7801\n<strong>CURLINFO_FILETIME<\/strong>:\n<strong>CURLINFO_TOTAL_TIME<\/strong>:\n<strong>CURLINFO_CONNECT_TIME<\/strong>:\n<strong>CURLINFO_NUM_CONNECTS<\/strong>: \u591a\u5c11\u4e2a\u8fde\u63a5\n<strong>CURLINFO_CONTENT_TYPE<\/strong>: \u4f8b\uff1atext\/html\n<strong>CURLINFO_REQUEST_SIZE<\/strong>:\n<strong>CURLINFO_HEADER_SIZE<\/strong>:\n<strong>CURLINFO_SIZE_DOWNLOAD<\/strong>: \u4e0b\u8f7d\u603b\u5b57\u8282\u91cf\n<strong>CURLINFO_SIZE_UPLOAD<\/strong>:\n<strong>CURLINFO_HTTPAUTH_AVAIL<\/strong>: \u63a5\u6536\u63a9\u7801\u8868\u660e\u8eab\u4efd\u9a8c\u8bc1\n<strong>CURLINFO_PROXYAUTH_AVAIL<\/strong>: \u63a5\u6536\u63a9\u7801\u8868\u660e\u4ee3\u7406\u8eab\u4efd\u9a8c\u8bc1\n<strong>CURLINFO_COOKIELIST<\/strong>:\n\u90e8\u4efd\u4f7f\u7528 INFO_ \u5982\uff1aINFO_COOKIELIST<\/pre>","protected":false},"excerpt":{"rendered":"<p><a href=\"http:\/\/pycurl.sourceforge.net\/download\/\">http:\/\/pycurl.sourceforge.net\/download\/<\/a> <a href=\"http:\/\/pycurl.sourceforge.net\/doc\/curlobject.html\">http:\/\/pycurl.sourceforge.net\/doc\/curlobject.html<\/a> wget http:&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,274],"tags":[],"class_list":["post-773","post","type-post","status-publish","format-standard","hentry","category-linux","category-python"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=773"}],"version-history":[{"count":6,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/773\/revisions"}],"predecessor-version":[{"id":775,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/773\/revisions\/775"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=773"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}