关于curl:curl-d-data

-d, --data <data>POST办法提交数据时,须应用--data来指定申请数据。和浏览器填充好表单点击提交按钮雷同。在没有指定内容类型的状况下,应用表单编码间接应用--data提交数据时,中文会乱码。 curl --verbose -data "name=eliminate" --data "hobby=play 足球football" localhost:8080/userAdd当--data呈现屡次时,零碎会主动用符号&拼接起来。(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button.This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.-d, --data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode.If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'.If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of thefile must already be URL-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar.

August 31, 2023 · 1 min · jiezi

关于curl:curl-X-request-command

-X, --request <command>curl 默认的http申请办法是GET。通常状况下,你并不需要指定这个选项,他会通过其余命令推导进去。应用这个选项来指定http的申请办法,其实没卵用,他并不会扭转curl命令的理论行为,你指定了GET,它并不一定应用GET办法发送申请。今天上代码。 (HTTP) Specifies a custom request method to use when communicating with the HTTP server.The specified request will be used instead of the method otherwise used (which defaults to GET).Read the HTTP 1.1 specification for details and explanations. Common additional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.Normally you don't need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated command line options.This option only changes the actual word used in the HTTP request, it does not alter the way curl behaves. So for example if you want to make a proper HEAD request, using -X HEAD will not suffice. You need to use the -I, --head option.(FTP) Specifies a custom FTP command to use instead of LIST when doing file lists with FTP.If this option is used several times, the last one will be used.

August 30, 2023 · 1 min · jiezi

关于curl:curl-i-include

-i, --includecurl www.baidu.com --include-i参数能够显示http response的头信息,连同网页代码一起。 (HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...

August 30, 2023 · 1 min · jiezi

关于curl:curl-o-output-file

-o, --output <file>惯例操作一:把一个申请的响应写入单个文件中curl www.baidu.com --output "baidu.txt"将会把百度首页的内容放入文件baidu.txt,baidu.txt在执行命令的当前目录生成。 惯例操作二:把多个申请的响应写入多个文件中(单个汇合变量)curl -v https://ai.baidu.com/ai-doc/FACE/{6k37c1nva,Yk37c1o30} --output "file_#1abc.txt"将会把两个接口https://ai.baidu.com/ai-doc/FACE/Okg7edktq,https://ai.baidu.com/ai-doc/FACE/6k37c1nva的内容别离存入file_Okg7edktqabc.txt,file_Yk37c1o30abc.txt文件中,大括号相当于汇合,外面的元素会替换掉指定的文件名中的#1字符。留神:此命令在linux下执行{}须要本义,即\{.....\} 惯例操作三:把多个申请的响应写入多个文件中(单个数组变量)curl https://ai.baidu.com/ai-doc/FACE/Yk37c1o3[0-5] --output "b_#1.txt"将会把六个接口: https://ai.baidu.com/ai-doc/FACE/Yk37c1o30https://ai.baidu.com/ai-doc/FACE/Yk37c1o32https://ai.baidu.com/ai-doc/FACE/Yk37c1o33https://ai.baidu.com/ai-doc/FACE/Yk37c1o34https://ai.baidu.com/ai-doc/FACE/Yk37c1o35https://ai.baidu.com/ai-doc/FACE/Yk37c1o36的响应别离存入以下文件 b_0.txtb_1.txtb_2.txtb_3.txtb_4.txtb_5.txt 惯例操作三:把多个申请的响应写入多个文件(多个汇合、多个数组变量)curl http://{site,host}.baidu.{one,two}.host[1-5].sina[0-5].com -o "#1_#2_#3_#4"请自行演示。 Write output to <file> instead of stdout.If you are using {} or [] to fetch multiple documents, you can use '#' followed by a number in the <file> specifier. Thatvariable will be replaced with the current string for the URL being fetched. Like in: curl http://{one,two}.site.com -o "file_#1.txt"or use several variables like: curl http://{site,host}.host[1-5].com -o "#1_#2"You may use this option as many times as the number of URLs you have.

August 30, 2023 · 1 min · jiezi

关于curl:curl-v-verbose

-v, --verbose以">"打头,示意申请头以"<"打头,示意响应头以"*"打头,示意curl命令提供的额定信息。 Makes the fetching more verbose/talkative. Mostly useful for debugging.A line starting with '>' means "header data" sent by curl, '<' means "header data" received by curl that is hidden in normal cases, and a line starting with '*' means additional info provided by curl.Note that if you only want HTTP headers in the output, -i, --include might be the option you're looking for.If you think this option still doesn't give you enough details, consider using --trace or --trace-ascii instead.This option overrides previous uses of --trace-ascii or --trace.Use -s, --silent to make curl quiet.

August 30, 2023 · 1 min · jiezi

关于curl:curl-H-header-header

-H, --header <header>原生申请头curl -v -X POST localhost:8081/health 自定义申请头curl -v -X POST localhost:8081/health --header "X-Custom-Header;" --header "token:sneaky" --header "Host: baidu:8081" --header "User-Agent:"通过图片可察看到: 可重写curl命令自带的申请头。curl命令外部自带的申请头Host: localhost:8081被批改成了Host: baidu:8081。可移除curl命令自带的申请头。curl命令外部自带的申请头User-Agent: curl/8.0.1,被通过自定义申请头--header "User-Agent:"移除了。可自定义申请值为空的申请头。自定义申请头X-Custom-Header:是空值,通过设置申请头为:--header "X-Custom-Header;"。能够同时增加多个自定义申请头。 服务器后盾输入 (HTTP) Extra header to use when getting a web page.You may specify any number of extra headers. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do.You should not replace internally set headers without knowing perfectly well what you're doing.Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:". If you send the custom header with no-value then its header must be terminated with a semicolon, such as -H "X-Custom-Header;" to send "X-Custom-Header:".curl will make sure that each header you add/replace is sent with the proper end-of-line marker, you should thus not add that as a part of the header content: do not add newlines or carriage returns, they will only mess things up for you.See also the -A, --user-agent and -e, --referer options.This option can be used multiple times to add/replace/remove multiple headers.

August 30, 2023 · 1 min · jiezi

关于curl:后端请求数据计算量过大导致给用户的返回结果过于漫长一次调优的过程

【我的项目背景形容】 有一个表格,形容的是Snapshot-1和Snapshot-2之间的比照,数据比照的后果是由后端算进去的,前端只有负责渲染就能够。后端返回的数据实质是一个“森林”,每棵“树”都是三层,别离是:type/ class name/ object name。因为每棵树的计算量比拟大,孩子节点也比拟多,所以在前端渲染的时候,应用懒加载做了优化,即只有当用户开展某层的时候才会call到后端申请数据。所以,页面第一次渲染的时候,显示的是森林里所有树的第一层。除了页面的数据展现,Diff表格还反对csv download,因为csv须要拿到全量的比照数据,也就是整片森林,所以当用户点击CSV下载的时候,会先call后端拿到全量数据,再csv format,最初输入。 【呈现问题】有用户反馈说:CSV下载等了良久都在loading,问怎么回事? 【排查过程】1.前述环境 咱们有本地开发环境(对应本人本地的数据库,能够操作后端代码and前端代码)用户呈现问题的是prod环境(本地的前端是无奈call到prod环境的DB的)2.找到瓶颈 关上用户的报告,的确数据量很大,点击csv download,感觉下载一个diff文件,大略须要30s左右的工夫。也就是说代码逻辑没有问题,就是慢。关上控制台,看数据返回工夫。其实工夫不是很长,只有7s,因而,工夫的瓶颈不在这里。 接下来,就是看api callback外面的解决逻辑有什么能够优化的中央了。然而,如何拿到用户的数据呢?因为本地开发环境是没有方法连上prod的数据库的。【解决方案】:能够在开发者模式下,拿到api返回的数据,并将其保留成json,在前端代码里import进来进行解决。然而,因为返回的后果过于宏大,response无奈load,“复制粘贴”的打算失败。 【解决方案】:右击url,找到Copy as cURL,并在命令的结尾加上“>> 1.txt”,能够将response后果间接输入到文件,而不是命令行,不便复制。 万事俱备,开始查看瓶颈。在csv format中的每个函数前面,console.log一个工夫戳,便于查看到底哪里比拟耗时。最终发现,sort函数占用了大量的工夫,因为有2层for循环。从新查看代码,其实call回来的api在后端解决的时候,其实曾经是排好程序的,因而,前端无需“多此一举”。综上所述,删除前端sort函数即可。(省略后续测试步骤......)【知识点回顾】 curl 是罕用的命令行工具,用来申请 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。有很多不同的命令行参数,不便开发者在cmd里申请api。

January 18, 2023 · 1 min · jiezi

关于curl:curl安装

一:windows下装置curl1:下载windows版本curl安装包依据你电脑的零碎抉择32位或64位,因为我的电脑是64位的,所以我抉择64位的安装包 curl下载地址:https://curl.haxx.se/download... 2:装置curl(1)将下载下来的压缩包解压到你想要装置的目录下,找到curl目录下的curl.exe文件 (2)将curl.exe文件所在门路退出到环境变量中,这是为了curl命令能够全局应用 (3)新建一个CURL_HOME变量,变量地址为curl.exe文件所在门路 (4)将CURL_HOME变量信息加到PATH变量中 3:判断curl是否装置胜利curl --version 装置胜利 二:linux下装置curl1:下载curl下载地址:https://curl.haxx.se/download... 你也能够下载旧版的curl:https://curl.haxx.se/download/ wget https://curl.haxx.se/download/curl-7.30.1.tar.gz2:装置curltar -xzvf  curl-7.30.1.tar.gz #解压cd curl-7.30.1./configuremake && make install3:检测是否装置胜利curl --version

November 1, 2022 · 1 min · jiezi

关于curl:国密curl的用法指南

1.curl是什么 cURL(客户端URL)是一个凋谢源代码的命令行工具,用来申请 Web和其余各种类型的服务器。curl有着大量的参数,罕用来测试/调试服务器的开发和排查等,堪称一个网络“神器”。 2.国密curl是什么 curl本身不反对国密SSL协定(TLCP)。程序员说:要有国密版curl,于是就有了国密版curl,哈哈,程序员就是软件世界的上帝啊。国密版curl,简称gmcurl,由国密SSL实验室(www.gmssl.cn)移植,并提供收费下载和应用。 3.国密curl应用(单向国密SSL)3.1 简略执行[root@206test ~]# ./gmcurlGM Version: 1.0.0 Ported by www.gmssl.cnOptions:--gmssl, use TLCP protocol--cert, use sm2 sig pem cert--key, use sm2 sig pem key--cert2, use sm2 enc pem cert--key2, use sm2 enc pem keycurl: try 'curl --help' or 'curl --manual' for more information3.2 简略拜访[root@206test ~]# ./gmcurl --gmssl -k https://ebssec.boc.cnGM Version: 1.0.0 Ported by www.gmssl.cnOptions:--gmssl, use TLCP protocol--cert, use sm2 sig pem cert--key, use sm2 sig pem key--cert2, use sm2 enc pem cert--key2, use sm2 enc pem key正文:1)--gmssl示意启用国密SSL2)-k示意不验证服务端证书 ...

July 20, 2022 · 17 min · jiezi

关于curl:cURL-作者回怼财富-500-强公司的白嫖要求-不付钱就闭嘴

近日,cURL 的作者 Daniel Stenberg 公布的一篇推文引起了热议。文中,他礼貌的“回怼”了来自500强公司对其技术支持“白嫖”的无理要求——“要么付钱,要么闭嘴!” 据悉,该事件的起因是一家美国《财产》500 强公司因去年 12 月份的 Apache Log4j 破绽事件,而发来了一封电子邮件(该公司或其客户可能正在应用 cURL)询问一系列问题,以理解 cURL 是否依赖于 Log4j,并要求 cURL 的作者须在收到这封邮件的 24 小时内尽快、收费地回复。 该邮件原文下方,这家财产 500 强公司(以NNNN代表)还列出了一系列有待 cURL 的作者 Daniel Stenberg 答复的问题: 贵公司是否产生过任何经证实的安全事件?如果有,哪些应用程序、产品、服务和相干版本受到影响?是否有任何 NNNN 的产品和服务受到影响?NNNN 非公开信息或个人信息是否受到影响?如果是,请立刻向 NNNN 提供受影响信息的细节。实现补救措施的时间表是什么?列出这些步骤,并包含每个步骤的日期。须要 NNNN 采取什么口头来实现这一补救措施?…… 收到这封邮件之后,cURL 的作者 Daniel Stenberg 感到非常好笑,因为他从未参加过任何 Log4j 的开发工作,也就是他和这件事件没有一点儿关系。 但既然邮件里要求他必须尽快回复,因而他也礼貌而“克服”的做了回答:“只有咱们签订了反对合同,我就会立刻回信”。同时,他也将对该事件放在了推特上“吐槽”: “如果你是一家价值数十亿美元的公司,当你关怀 Log4j 的时候,为什么不给那些你从未领取过任何费用的 OSS 作者发邮件要求他们在 24 小时内收费回复大量信息并出示收到的邮件呢?” cURL 作者“回怼”:邮件里的内容无知水平令人震惊可能是这件事件真的有点太莫名其妙了, Daniel Stenberg 随后还专门写了一篇博文评估这件事件: “2022 年 1 月 21 日星期五,我收到了这封电子邮件。我在推特上发了这条音讯,而后来到了。 这封邮件来自一家价值数十亿美元的《财产》500强公司,该公司显然可能会应用蕴含我的代码的产品,或者他们可能有这样的客户。谁晓得呢? 我猜他们这样做是出于法规听从性的起因,他们“遗记”了他们的开源组件不是由“合作伙伴”主动提供的,他们能够简略地要求提供这些信息。 我很简短地回复了这封邮件,并示意一旦咱们签订了反对合同,我很乐意回复详细信息。 我认为这可能是开源金字塔模式的一个很好的例子,高层的人基本不思考如何保护底层。不必放心房子所在的高空就能够盖房子。” ...

January 26, 2022 · 1 min · jiezi

关于curl:curl-作者-Daniel-Stenberg-计划将为-curl-添加原生支持-JSON

近日,curl 作者 Daniel Stenberg 打算将为 curl 增加原生反对 JSON ,并给出了三个理由。 在 REST APIs 等畛域,发送 JSON 是很广泛的做法当被问及人们抉择 curl 代替计划的思考因素时,“易于应用 JSON”是常见的答案在 Stack Overflow 等网站上,因为 JSON 应用了双引号,而 Shell 不会在单引号内扩大变量从而导致许多人无奈应用 cURL 发送正确的 JSON 和正确援用 JSONDaniel 示意,因为他不常常发送 JSON,所以不适宜齐全靠他来设计这个性能。他须要更多其他人的帮忙来让这个性能尽可能地有用。 简略来说,Daniel 打算减少两个命令行选项: 发送已格式化的 JSON 作为 -d 的快捷方式,并附带相匹配的 Accept header构建 JSON request body 进行发送目前 Daniel 曾经在curl wiki中起草了他更新的概念,同时创立了讨论区。感兴趣的敌人们能够积极参与探讨。 curl wiki 链接:https://github.com/curl/curl/... 讨论区链接:https://github.com/curl/curl/... 对于 cURLcURL是一个开源我的项目,次要的产品是curl(命令行工具)和libcurl(C语言的API库),两者性能均是:基于网络协议,对指定URL进行网络传输。 curl 是一款利用 URL 语法在命令行下工作的文件传输工具,1997 年首次发行。它反对文件上传和下载,所以是一款综合传输工具。curl 蕴含用于程序开发的 libcurl,可解决各种状况的认证页面,如交互式的让用户输出明码等,目前可在MIT许可证下应用。

January 22, 2022 · 1 min · jiezi

关于curl:php-curl-请求https接口证书问题

php 在windows上面应用curl申请一个https须要配置证书,具体请看代码: php.ini配置 证书下载http://curl.haxx.se/ca/cacert...

December 18, 2021 · 1 min · jiezi

关于curl:命令行搞一切之curl-的开心应用

查看本人的外网ip地址很多网站都提供这个性能,如: curl -s ip.liquidweb.comcurl checkip.amazonaws.comcurl ifconfig.mecurl httpbin.org/ip生成一个二维码网址是 qrenco.de,即 QR encode,是不是很好记呢。 % curl qrenco.de/bixuebihui.com██████████████████████████████████████████████████████████████ ▄▄▄▄▄ █ ▄ █ █ ▄▄▄▄▄ ████████ █ █ █ ▀▀ █ █ █ ████████ █▄▄▄█ █▀▀██ █ █▄▄▄█ ████████▄▄▄▄▄▄▄█▄▀ █▄█▄▄▄▄▄▄▄████████ ▀▀ ▄▄▀▀ █▄█▀█▄▀▄▄ ▄████████▀ █▄▀ ▄▀▄▀ █▀▀██ ██▄▀███████████▄▄█▄▄ ▀▀▄██▀█ ▄█ ▄████████ ▄▄▄▄▄ █▀▄▄█▀ █▀▄▄█ ▀████████ █ █ █▄▀▀█▄ ██▀ ▀▀▀████████ █▄▄▄█ █▀ ▀▀▄██ ████████████▄▄▄▄▄▄▄█▄██▄█▄█▄████▄██████████████████████████████████████████████████████████████生成是显示在页面上看上去有点问题,命令行里还是能够扫到的。 查个字典curl dict.org/d:entropy |lesscurl dict.org/d:curl |less抽奖时搞个偏心随机数curl "https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new"打小抄curl http://cht.sh/java会返回罕用的java的一些应用提醒。 如 curl http://cht.sh/js/promise/* * understanding javascript promise object * * Promise execution is asynchronous, which means that it's executed, but * the program won't wait until it's finished to continue with the rest * of the code. * * Basically, your code is doing the following: * * 1. Log 'Hi' * 2. Create a promise * 3. Execute the promise * 4. Log 'zami' * 5. Promise is resolved and logs 'There'. * If you want it to print 'Hi there, zami', you will have to */myPromise.then(function (result) { // Resolve callback. console.log(result); console.log('zami');}, function (result) { // Reject callback. console.error(result);});/* [Alberto Rivera] [so/q/39458201] [cc by-sa 3.0] */中文OCR辨认这个网站有收费可用的api: https://ocr.space/OCRAPI通过curl简略调用能够辨认图片上的文字,能够指定语言。免费版每天可用500次,文件最大1M。反对20几种语言,包含中文。 ...

September 19, 2021 · 3 min · jiezi

关于curl:curl网站开发指南

curl是一种命令行工具,作用是收回网络申请,而后失去和提取数据,显示在"规范输入"(stdout)下面。 它反对多种协定,上面举例解说如何将它用于网站开发。 一、查看网页源码 间接在curl命令后加上网址,就能够看到网页源码。咱们以网址www.sina.com为例(抉择该网址,次要因为它的网页代码较短): curl www.sina.com<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>301 Moved Permanently</title> </head> <body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.sina.com.cn/">here</a>.</p> </body></html>如果要把这个网页保留下来,能够应用-o参数,这就相当于应用wget命令了。 curl -o [文件名] www.sina.com二、主动跳转 有的网址是主动跳转的。应用-L参数,curl就会跳转到新的网址。 curl -L www.sina.com键入下面的命令,后果就主动跳转为www.sina.com.cn。 三、显示头信息 -i参数能够显示http response的头信息,连同网页代码一起。 curl -i www.sina.com HTTP/1.0 301 Moved Permanently Date: Sat, 03 Sep 2011 23:44:10 GMT Server: Apache/2.0.54 (Unix) Location: http://www.sina.com.cn/ Cache-Control: max-age=3600 Expires: Sun, 04 Sep 2011 00:44:10 GMT Vary: Accept-Encoding Content-Length: 231 Content-Type: text/html; charset=iso-8859-1 Age: 3239 X-Cache: HIT from sh201-9.sina.com.cn Connection: close <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.sina.com.cn/">here</a>.</p> </body></html>-I参数则是只显示http response的头信息。 ...

June 12, 2021 · 2 min · jiezi

关于curl:通过CURL获取本机指定IP-地址相关信息

curl获取本机代理IP地址 $curl ip.sb101.*.*.112$curl ip.gs101.*.*.112curl获取IP地址+地区 $curl ipinfo.io{ "ip": "101.*.*.112", "city": "Kowloon", "region": "Kowloon City", "country": "HK", "loc": "22.3167,114.1833", "org": "AS132203 Tencent Building, Kejizhongyi Avenue", "timezone": "Asia/Hong_Kong", "readme": "https://ipinfo.io/missingauth"}% curl获取本机IP地址 $curl cip.ccIP : 125.*.*.87地址 : 中国 天津运营商 : 联通数据二 : 天津市 | 联通数据三 : URL : http://www.cip.cc/125.*.*.87curl查问指定IP信息 $curl cip.cc/114.114.114.114IP : 114.114.114.114地址 : 114DNS.COM 114DNS.COM数据二 : 江苏省南京市 | 南京信风网络科技有限公司GreatbitDNS服务器数据三 : 中国江苏南京URL : http://www.cip.cc/114.114.114.114$curl cip.cc/127.0.0.1IP : 127.0.0.1地址 : 本机地址 本机地址数据二 : 本机地址数据三 : 内网IP | 内网IPURL : http://www.cip.cc/127.0.0.1

April 6, 2021 · 1 min · jiezi

关于curl:failed-to-connect-to-rawgithubcom-port-443

curl: (7) failed to connect to raw.github.com port 443: connection refused 如何解决? 1、 2、网络 -> 高级 3、批改dns:8.8.8.8 done!

January 29, 2021 · 1 min · jiezi

用-cURL-请求测试-ETag-浏览器缓存

作者:Nic Raboy翻译:疯狂的技术宅原文:https://www.thepolyglotdevelo...未经允许严禁转载最近,我一直在玩Netlify,结果我对内容交付网络(CDN)常见的缓存策略越来越熟悉。有一种将 ETag标识符用于 Web 资源的策略。 简而言之,ETag 标识符是一个值,通常是一个散列,代表特定 Web 资源的版本。该资源与 ETag 值一起缓存在浏览器中,并且服务器会在确定特定的缓存资源是否已更改时使用该值。 我们将探索怎样通过简单的 cURL 请求用 ETag 标识符模拟浏览器发出的请求,而是。 首先,我们将请求资源: $ curl -I https://www.thepolyglotdeveloper.com/css/custom.min.cssHTTP/2 200 accept-ranges: bytescache-control: public, max-age=0, must-revalidatecontent-length: 7328content-type: text/css; charset=UTF-8date: Wed, 04 Sep 2019 00:41:04 GMTstrict-transport-security: max-age=31536000etag: "018b8b0ecb632aab770af328f043b119-ssl"age: 0server: Netlifyx-nf-request-id: 65a8e1aa-03a0-4b6c-9f46-51aba795ad83-921013在上述请求中,我仅从响应中请求了标头信息。对于本文,响应体回复的内容对我们而言并不重要。 注意 cache-control 和 etag 标头以及响应代码。 在 Netlify 下,cache-control 标头告诉浏览器缓存资源,但也不信任缓存。这样做是为了使客户端始终尝试获取最新资源。 etag 标头代表资源的版本,并随将来的请求一起发送。如果服务器回复说两次请求之间的 etag 没有改变,则响应将会带有 304 代码,从而将使用缓存的资源。 因此,让我们用 cURL 检查一下资源是否已进行了更改: $ curl -I -H 'If-None-Match: "018b8b0ecb632aab770af328f043b119-ssl"' https://www.thepolyglotdeveloper.com/css/custom.min.cssHTTP/2 304 date: Wed, 04 Sep 2019 00:53:24 GMTetag: "018b8b0ecb632aab770af328f043b119-ssl"cache-control: public, max-age=0, must-revalidateserver: Netlifyx-nf-request-id: eca29310-c9bf-4742-87e1-3412e8852381-2165939对相同资源的新请求,将包含 If-None-Match 标头,其值为前一个请求的 etag 哈希。 ...

October 9, 2019 · 2 min · jiezi

YurunHttp-v310新增-Cookie-管理机制单元测试支持

YurunHttp 是开源的 PHP HTTP 类库,支持链式操作,简单易用。 支持所有常见的 GET、POST、PUT、DELETE、UPDATE 等请求方式,支持上传下载、设置和读取 header、Cookie、请求参数、失败重试、限速、代理、证书等。 3.x 版完美支持 Curl、Swoole 协程。 我们有完善的在线技术文档:http://doc.yurunsoft.com/Yuru... API 文档:https://apidoc.gitee.com/yuru... Gitee:https://gitee.com/yurunsoft/Y... Github:https://github.com/Yurunsoft/... git仓库中test目录里是示例代码! 更新日志(v3.1.0):新增: 新增 CookieManager,用于管理一个实例下的会话。现在同一个HttpRequest类实例,会自动管理 Cookie。 增加测试用例(PHP5.4 - PHP7.3)、示例代码 优化: 现在只有状态码为301、302、303,才更改重定向请求方法为 GET 优化 StatusCode 类 Swoole 重定向地址的 host、port、scheme 与上一个地址保持一致的话,复用 $client 同一个 HttpRequest 对象重复请求时,Curl 资源不再重新 init Uri->getPort() 不再根据协议自动返回缺省端口新增 Uri::getServerPort() 方法获取端口,支持获取缺省 Uri::getDomain() 方法改为静态方法 优化 close()、__destruct() Curl CURLOPT_COOKIEJAR 默认值改为 php://memory,不再写入文件 优化 Curl header 处理性能 修复: 修复 Swoole Handler Host 不带端口号问题Composer本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 composer.json 中加入下面的内容 { "require": { "yurunsoft/yurun-http": "~3.1" }}然后执行 composer update 安装。 ...

June 25, 2019 · 1 min · jiezi

如何使用curl访问k8s的apiserver

使用TOKEN授权访问api-server在k8s运维场景中比较常见, apiserver有三种级别的客户端认证方式 1,HTTPS证书认证:基于CA根证书签名的双向数字证书认证方式 2,HTTP Token认证:通过一个Token来识别合法用户 3,HTTP Base认证:通过用户名+密码的认证方式 通常的运维场景使用第二种Token较为方便Token的权限是关联service account, # kubectl describe secrets admin-token-2q28f -n kube-systemName: admin-token-2q28fNamespace: kube-systemLabels: <none>Annotations: kubernetes.io/service-account.name: admin kubernetes.io/service-account.uid: 93316ffa-7545-11e9-b617-00163e06992dType: kubernetes.io/service-account-tokenData====ca.crt: 1419 bytesnamespace: 11 bytestoken: eyJhbGciOiJ******Service Account 的权限来自Clusterrolebinding-->ClusterRole # kubectl describe serviceaccount admin -n kube-systemName: adminNamespace: kube-systemLabels: <none>Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","kind":"ServiceAccount","metadata":{"annotations":{},"name":"admin","namespace":"kube-system"}}Image pull secrets: <none>Mountable secrets: admin-token-2q28fTokens: admin-token-2q28fEvents: <none>通过clusterrolebinding 可以拿到ClusterRole对应的rolename # kubectl get clusterrolebinding admin -o yamlapiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"rbac.authorization.k8s.io/v1beta1","kind":"ClusterRoleBinding","metadata":{"annotations":{},"name":"admin"},"roleRef":{"apiGroup":"rbac.authorization.k8s.io","kind":"ClusterRole","name":"cluster-admin"},"subjects":[{"kind":"ServiceAccount","name":"admin","namespace":"kube-system"}]} creationTimestamp: 2019-05-13T06:08:49Z name: admin resourceVersion: "1523" selfLink: /apis/rbac.authorization.k8s.io/v1/clusterrolebindings/admin uid: 93356439-7545-11e9-b617-00163e06992droleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-adminsubjects:- kind: ServiceAccount name: admin namespace: kube-system这个role是什么权限? ...

June 24, 2019 · 2 min · jiezi

Swoole-44支持-CURL-协程化

在4.4之前的版本中,Swoole一直不支持CURL协程化,在代码中无法使用curl。由于curl使用了libcurl库实现,无法直接hook它的socket,4.4版本使用Swoole\Coroutine\Http\Client模拟实现了curl的API,并在底层替换了curl_init等函数的C Handler。 提示CURL Hook的特性尚处于试验阶段,请勿在生产环境中直接使用暂不支持文件上传、CURL Multi仍然需要依赖curl,请务必安装curl扩展支持的特性列表GET/POSTHeaderCookieHttps经过验证Guzzle CURL完全可以使用开启使用Runtime::enableCoroutine来开启CURL Hook。 默认不开启CURL HookSwoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_CURL);使用$n = 10;while($n--) { go(function () { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.xinhuanet.com/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $output = curl_exec($ch); if ($output === FALSE) { echo "CURL Error:" . curl_error($ch); } curl_close($ch); echo strlen($output) . " bytes\n"; });}要将上面两段代码合并到一个文件中执行运行结果htf@LAPTOP-0K15EFQI:~/swoole-src/examples$ time php curl.php177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytesreal 0m0.534suser 0m0.031ssys 0m0.297s可以看到整个程序是并行的,进程没有任何阻塞。 strace 跟踪使用strace跟踪发现,所有系统调用均变成epoll+socket的异步非阻塞调用了。 ...

June 5, 2019 · 10 min · jiezi

linux-curl请求时参数被截断

当我在curl一个url时,发现在后端PHP环境使用xdebug时,只能捕获第一个参数: curl test.baidu.com/oss/index.php?r=info/data/query&username=xxx&password=xxx# 在后端url被截断,只能捕获到第一个参数$_GET: array(1) r: "info/data/query"这导致了我的认证失败,无法获取正确的数据。 其实这里的原因是在shell 命令中&符号有特殊的含义,而并不只是url参数的连接符。因此,我们有两种解决方法: # 方法一:转义,加上\符curl test.baidu.com/oss/index.php?r=info/data/query\&username=xxx\&password=xxx# 方法二:包装,在url外加上引号,用字符串处理curl 'test.baidu.com/oss/index.php?r=info/data/query&username=xxx&password=xxx'重新测试,解决问题。 参考资料Linux curl get请求参数多个参数被截断的解决方法:https://blog.csdn.net/top_cod...

April 28, 2019 · 1 min · jiezi

【项目推荐】Guzzle - 简单易用的 PHP HTTP 客户端

Guzzle 介绍Guzzle 是一款简单、易用的 PHP HTTP 客户端。它可以快速的集成到 WEB 项目中,帮助我们非常方便的发送 HTTP 请求。Guzzle 特点接口简单支持使用 curl,PHP streams,sockets等各种方式。支持同步和异步请求遵循 PSR7 规范,可以集成其他的符合 psr7 规范的类库,自定义处理逻辑安装使用 composer 安装,非常方便composer require –prefer-dist guzzlehttp/guzzle快速入门1.初始化客户端use GuzzleHttp\Client;options = [ ‘base_uri’ => ‘http://guzzle.testhttp.com’, ‘connect_timeout’ => 1, ’timeout’ => 3,];$client = new Client($options);2.发送body请求$client->request(‘POST’, ‘/post’, [‘body’ => ’this is post body’]);3.发送表单请求$client->request(‘POST’, ‘/post’, [ ‘form_params’ => [ ‘user_id’ => 1, ‘user_name’ => ‘hello world!’ ]]);4.json 请求$client->request(‘POST’, ‘/post’, [‘json’ => [‘data’ => ‘hello world!’]]);5.使用cookie$params = [‘json’ => [‘data’ => ‘hello world!’]];$cookieJar = CookieJar::fromArray([‘cookieName’ => ’testCookie’], ‘guzzle.testhttp.com’);$param[‘cookies’] = $cookieJar;$client->request(‘POST’, ‘/post’, $params);6.multipart$client->request(‘POST’, ‘/post’, [ ‘multipart’ => [ [ ’name’ => ‘baz’, ‘contents’ => fopen(’/path/to/file’, ‘r’) ], [ ’name’ => ‘qux’, ‘contents’ => fopen(’/path/to/file’, ‘r’), ‘filename’ => ‘custom_filename.txt’ ], ]]);7.异步请求use Psr\Http\Message\ResponseInterface;use GuzzleHttp\Exception\RequestException;$promise = $client->requestAsync(‘POST’, ‘/post’, [‘json’ => [‘data’ => ‘hello world!’]]);$promise->then( function (ResponseInterface $res) { echo $res->getStatusCode() . “\n”; }, function (RequestException $e) { echo $e->getMessage() . “\n”; echo $e->getRequest()->getMethod(); });8.并发请求use GuzzleHttp\Client;use GuzzleHttp\Promise;$client = new Client([‘base_uri’ => ‘http://guzzle.testhttp.com/’]);// Initiate each request but do not block$promises = [ ‘a’ => $client->requestAsync(‘POST’, ‘/post’, [‘json’ => [‘data’ => ‘hello test1!’]]), ‘b’ => $client->requestAsync(‘POST’, ‘/post’, [‘json’ => [‘data’ => ‘hello test2!’]]), ‘b’ => $client->requestAsync(‘POST’, ‘/post’, [‘json’ => [‘data’ => ‘hello test3!’]]),];// Wait on all of the requests to complete.$results = Promise\unwrap($promises);// You can access each result using the key provided to the unwrap// function.echo $results[‘a’]->getBody()->getContents(); // body 也有实现 __toString()调用getContents() echo $results[‘b’]->getHeader(‘Content-Length’);附录项目地址官方文档中文文档 ...

April 16, 2019 · 2 min · jiezi

php 使用Curl传递json资料给对方及显示对方回传的json(Json格式/ API串接/ HttpRequest)

本教学使用环境介绍伺服器端:Ubuntu 18.04 LTS资料库:Mariadb 10.1.34(Mysql)语言版本:php 7.3本机端:MacOS High Sierrafunction httpRequest($api, $data_string) { $ch = curl_init($api); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( ‘Content-Type: application/json’, ‘Content-Length: ’ . strlen($data_string)) ); $result = curl_exec($ch); curl_close($ch); return json_decode($result);}将以下资料变成json格式传输传给对方接应的 <https-api-url>$data = array( “id” => $id, “field” => $field);$data = httpRequest(’<https-api-url>’, json_encode($data));要印出对方回的 json key and value 内容时echo $data->{‘message’};如果对方回的是json array,使用foreach接应即可就能够印出回圈,对方回传多少笔就印多少笔foreach ($data as $value) { echo $value[‘message’];}可以使用sizeof查看object的长度,轻松做判断echo sizeof($data); // int如果对方回的不是json只是直接传 body 过来将上面的function中的return json_decode($result);改为return $result;然后直接印出即可echo $data;Line ID:ianmacQQ:1258554508 ...

April 2, 2019 · 1 min · jiezi

ubuntu上安装curl后无法使用

今天准备在我的ubuntu上安装curl玩一玩,在ubuntu上安装curl可以参考:curl 安装安装成功之后,我使用:curl –version判断curl是否安装成功时,发现报错,curl无法使用:解决方法:1:找到curl安装地址: find / -name curl可以知道curl地址为/usr/local/bin目录下2:修改/etc/ld.so.conf.d/目录下信息在/etc/ld.so.conf.d/目录下新增一个以.conf后缀的文件vim bin.conf在bin.conf文件中添加curl安装地址3:更新/etc/ld.so.cache文件sudo ldconfig这时候再次执行curl –version就可以看到curl安装版本,可以使用curl方法了

February 18, 2019 · 1 min · jiezi

PHP的CURL功能扩展基本用法

PHP的curl功能提供了很多函数,需要将这些函数按特定的步骤组合到一起,我们先来了解下PHP建立curl请求的基本步骤。$ch = curl_init(); // 创建一个新的CURL资源赋给变量$ch curl_setopt($ch, CURLOPT_URL, $url); // 设置URL$response = curl_exec($ch); // 执行,获取URL并输出到浏览器curl_close($ch); // 释放资源如果我们希望获取内容但不输出,可以使用 CURLOPT_RETURNTRANSFER 参数,并设置其值为非0或者true值。代码如下:curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);我们可以通设置函数curl_setopt()的不同参数,可以获得不同的结果,这也是CURL扩展的强大之处。curl_setopt()函数的常用参数选项具体可查阅官方文档,此处就不列举。下面是我常用的curl get和post请求的方法:get请求:public function httpGet(string $url = ‘’) { // 记录请求信息的日志 // todo try { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); //https 请求 if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == “https”) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } $response = curl_exec($ch); $errorCode = curl_errno($ch); curl_close($ch); if (!empty($errorCode)) { // 可记录错误码日志 return null; } // 记录返回结果日志 return $response; } catch (\Exception $e) { $errorLog = [ ‘msg’ => $e->getMessage(), ’trace’ => $e->getTraceAsString(), ‘data’ => [ ‘url’ => $url, ] ]; // 记录错误日志 return null; } }POST请求:public function httpPost(string $url = ‘’, array $data = []) { // 记录请求信息的日志 // todo try { $jsonData = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_HTTPHEADER, [ ‘Content-Type: application/json; charset=utf-8’, ‘Content-Length:’ . strlen($jsonData) ]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //https 请求 if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == “https”) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $result = curl_exec($curl); $errorCode = curl_errno($curl); curl_close($curl); if (!empty($errorCode)) { // 可记录错误码日志 return null; } // 记录返回结果日志 return json_decode($result, true); } catch (\Exception $e) { $errorData = [ ‘msg’ => $e->getMessage(), ’trace’ => $e->getTraceAsString(), ‘data’ => [ ‘url’ => $url, ‘postData’ => $data ] ]; // 记录错误日志 return null; } }欢迎各位朋友进行交流。 ...

January 5, 2019 · 2 min · jiezi

Linux升级wget/curl用于下载https文件的过程

因为需要提升服务器的性能以及支持mysql更新版本的某些特性,因此决定升级mysql版本从5.1.30到8.0,目标确定下来就开始干。Mysql安装方式选择在Linux上安装应用,一般有三种方式,优劣对比分别为:因此我们选择二进制安装,安装简单、方便,支持多个Mysql版本同时存在。在Linux上安装二进制版本的应用,统一为三步:// 通过配置自动生成文件./configure// 编译文件make// 检查自测单元,看编译是否通过,可以省略该步,不影响安装make check// 安装make install卸载通过二进制安装的程序:// 方式一: 在编译目录里执行卸载make uninstall// 方式二:找到安装目录,然后删除,如nettle程序$find / -name nettle/usr/include/nettlerm -rf /usr/include/nettlewget不支持https我们可以在mysql官网下载最新版本的mysql8.0.13二进制文件,注意官网提供的下载链接是https协议的,当我们在服务器执行下载命令:// 使用wget或者curl来下载文件wget https://dev.mysql.com/downloads/file/?id=480751curl -O https://dev.mysql.com/downloads/file/?id=480751会报错:// wget 加上–no-check-certificate 依然不可以$wget https://dev.mysql.com/downloads/file/?id=480751--2018-12-12 16:57:54– https://dev.mysql.com/downloads/file/?id=480751Resolving dev.mysql.com (dev.mysql.com)… 137.254.60.11Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443… connected.GnuTLS: A TLS fatal alert has been received.GnuTLS: received alert [40]: Handshake failedUnable to establish SSL connection.// curl 加上–insecure依然不可以$curl https://dev.mysql.com/downloads/file/?id=480751curl: (35) SSL connect error根据网上查询到的答案,原因均为版本过低,当前的版本不支持https协议的下载:So the error actually happens with www.coursera.org and the reason is missing support for SNI. You need to upgrade your version of wget.当前的版本:$wget –versionGNU Wget 1.16.3 built on linux-gnu.+digest +https +ipv6 +iri +large-file +nls +ntlm +opie -psl +ssl/gnutls Wgetrc: /usr/local/etc/wgetrc (system)Locale: /usr/local/share/locale Compile: gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/usr/local/etc/wgetrc" -DLOCALEDIR="/usr/local/share/locale" -I. -I../lib -I../lib -DHAVE_LIBGNUTLS -DNDEBUG Link: gcc -DHAVE_LIBGNUTLS -DNDEBUG -lpcre -lnettle -lgnutls -lz -lidn -lrt ftp-opie.o gnutls.o http-ntlm.o ../lib/libgnu.a Copyright (C) 2014 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later<http://www.gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.Originally written by Hrvoje Niksic <hniksic@xemacs.org>.Please send bug reports and questions to <bug-wget@gnu.org>.——————$curl.7.19.7 –versioncurl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz wget升级既然是版本过低,升级即可,直接安装新版本的wget,然后卸载掉原有的wget文件即可。下载完成1.20版本之后// 获得文件wget-1.20.tar.gzwget http://mirror.sergal.org/gnu/wget/wget-1.20.tar.gz// 解压缩tar -xzvf wget-1.20.tar.gz// 进入解压后的文件夹cd wget-1.20// 开始配置./configure// 然而报错了:…checking for GNUTLS… noconfigure: error: Package requirements (gnutls) were not met:No package ‘gnutls’ foundConsider adjusting the PKG_CONFIG_PATH environment variable if youinstalled software in a non-standard prefix.Alternatively, you may set the environment variables GNUTLS_CFLAGSand GNUTLS_LIBS to avoid the need to call pkg-config.See the pkg-config man page for more details.报错信息显示我们没有安装gnutls依赖,需要继续进行安装,更为详细的报错信息,可以查看config.log:// 查看详细报错信息vim config.log…PKG_CONFIG=’/usr/local/bin/pkg-config’…configure:44443: checking for GNUTLSconfigure:44450: $PKG_CONFIG –exists –print-errors “gnutls"Package gnutls was not found in the pkg-config search path.Perhaps you should add the directory containing gnutls.pc'to the PKG_CONFIG_PATH environment variableNo package 'gnutls' foundconfigure:44453: $? = 1configure:44467: $PKG_CONFIG --exists --print-errors "gnutls"Package gnutls was not found in the pkg-config search path.Perhaps you should add the directory containing gnutls.pc’to the PKG_CONFIG_PATH environment variableNo package ‘gnutls’ foundconfigure:44470: $? = 1configure:44484: result: noNo package ‘gnutls’ foundconfigure:44500: error: Package requirements (gnutls) were not met:No package ‘gnutls’ foundConsider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables GNUTLS_CFLAGS and GNUTLS_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.这里可以看出配置脚本实际是执行了:$ /usr/local/bin/pkg-config –exists –print-errors “gnutls"Package gnutls was not found in the pkg-config search path.Perhaps you should add the directory containing gnutls.pc'to the PKG_CONFIG_PATH environment variableNo package 'gnutls' found安装gnutls库gnutls全称 GNU Transport Layer Security Library,即基于GNU版权协议的传输层安全协议,是wget支持https中的ssl协议的基础库。我们可以在官方提供的镜像库里快速下载并安装:// 下载gnutls二进制文件wget http://www.ring.gr.jp/pub/net/gnupg/gnutls/v3.6/gnutls-3.6.4.tar.xz// 解压xz文件xz -d gnutls-3.6.4.tar.xztar -xvf gnutls-3.6.4.tarcd gnutls-3.6.4./configure// 报错:...checking for NETTLE... noconfigure: error: *** *** Libnettle 3.4 was not found.// 如果觉得可能不安全,可以下载md5签名文件验证文件,但是这个文件验证后发现签名过期了,所以没办法验证了wget http://www.ring.gr.jp/pub/net...gpg --verify gnutls-3.6.4.tar.xz.sig gnutls-3.6.4.targpg --recv-key F1679A65gpg --verify --verbose gnutls-3.6.4.tar.xz.sig gnutls-3.6.4.tar查看详细报错信息:$ vim config.log...configure:10032: checking for NETTLEconfigure:10039: $PKG_CONFIG --exists --print-errors "nettle &gt;= 3.4"Package nettle was not found in the pkg-config search path.Perhaps you should add the directory containing nettle.pc’to the PKG_CONFIG_PATH environment variableNo package ’nettle’ foundconfigure:10042: $? = 1configure:10056: $PKG_CONFIG –exists –print-errors “nettle >= 3.4"Package nettle was not found in the pkg-config search path.Perhaps you should add the directory containing nettle.pc'to the PKG_CONFIG_PATH environment variableNo package 'nettle' foundconfigure:10059: $? = 1configure:10073: result: noNo package 'nettle' foundconfigure:10090: error: *** *** Libnettle 3.4 was not found.结果显示我们需要3.4版本以上的Libnettle库,继续安装。安装Libnettle库Nettle库是用于跨平台的底层密码库,包含加密和解密的不同算法。我们下载并安装nettle库:wget ftp://ftp.gnu.org/gnu/nettle/nettle-3.4.1.tar.gztar -xzvf nettle-3.4.1.tar.gzcd nettle-3.4.1./configure// 安装成功...configure: summary of build options: Version: nettle 3.4.1 Host type: x86_64-unknown-linux-gnu ABI: 64 Assembly files: x86_64 Install prefix: /usr/local Library directory: ${exec_prefix}/lib64 Compiler: gcc Static libraries: yes Shared libraries: yes Public key crypto: no Using mini-gmp: no Documentation: yesmakemake install根据官方文档,我们安装完成后应该会有两个文件lib{hogweed,nettle}.so,然而我们只能发现其中一个:make install &amp;&amp;chmod -v 755 /usr/lib/lib{hogweed,nettle}.so &amp;&amp;install -v -m755 -d /usr/share/doc/nettle-3.4.1 &amp;&amp;install -v -m644 nettle.html /usr/share/doc/nettle-3.4.1$ ll | grep '\.so'-rwxr-xr-x 1 root root 3675341 Dec 12 19:15 libnettle.so$ ll | grep weed-rw-rw-r-- 1 work work 529 Dec 10 15:30 hogweed.pc-rw-r--r-- 1 work work 590 Nov 19 2017 hogweed.pc.in-rw-rw-r-- 1 work work 298 Dec 10 15:30 libhogweed.map-rw-r--r-- 1 work work 338 Nov 19 2017 libhogweed.map.in少了一个libhogweed.so文件,稍后我们编译gnutls时会发现这个导致的问题。继续编译gnutls既然nettle安装完成了,我们可以继续安装gnutls:./configure...configure: error: *** *** Libnettle 3.4 was not found.依然报错缺失库,但我们明明已经安装了,为什么找不到呢?我们用包管理工具查找一下:$ pkg-config --modversion nettlePackage nettle was not found in the pkg-config search path.Perhaps you should add the directory containing nettle.pc’to the PKG_CONFIG_PATH environment variableNo package ’nettle’ found我们找下这个nettle.pc刚才安装到哪里去了:$ locate nettle.pc/home/work/lib/nettle-3.4.1/nettle.pc/home/work/lib/nettle-3.4.1/nettle.pc.in/usr/lib64/pkgconfig/nettle.pc/usr/local/lib64/pkgconfig/nettle.pc而我们pkg-config默认的管理包检索路径为/usr/lib/pkgconfig,所以无法正常找到,参考pkgconfig文档,有两种方案:// 方案一:链接该文件到默认目录中ln -s /usr/local/lib64/pkgconfig/nettle.pc /usr/lib/pkgconfig/nettle.pc // 方案二:全局变量中更改包的检索路径(只在本次终端窗口生效,退出后恢复,所以只能临时使用一下)$ echo $PKG_CONFIG_PATH$ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/$ echo $PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/// 任一方案执行后结果$ pkg-config –modversion nettle3.4.1此时,我们继续安装:$ ./configure…checking for NETTLE… yeschecking for HOGWEED… noconfigure: error: *** *** Libhogweed (nettle’s companion library) was not found. Note that you must compile nettle with gmp support.可以看到,我们的nettle库已经安装成功,但是hogweed却检查没有找到,提示中也写明了libhogweed需要字gmp库已经安装完成的情况下重新编译nettle才可以被安装。有人提出过相关的问题,我们也可以从官网文档上更详细的知道这个Nettle对于libhogweed的依赖:5 LinkingNettle actually consists of two libraries, libnettle and libhogweed. The libhogweed library contains those functions of Nettle that uses bignum operations, and depends on the GMP library. With this division, linking works the same for both static and dynamic libraries.If an application uses only the symmetric crypto algorithms of Nettle (i.e., block ciphers, hash functions, and the like), it’s sufficient to link with -lnettle. If an application also uses public-key algorithms, the recommended linker flags are -lhogweed -lnettle -lgmp. If the involved libraries are installed as dynamic libraries, it may be sufficient to link with just -lhogweed, and the loader will resolve the dependencies automatically.总而言之,就是没有libhogweed.so这个文件不行,而它只能由nettle进行安装。根据nettle库官方资料显示,libhogweed.so应该在nettle安装时被自动生成,然而我们在上面的安装过程中并没有生成。那是不是因为我没有安装gmp导致的呢?安装gmp库我们下载gmp库并安装,可以在编译Nettle的config.log中查看有一条warning,指明了版本需求:$ vim config.log…configure:6583: result: noconfigure:6594: WARNING: GNU MP not found, or too old. GMP-6.0 or later is needed, see https://gmplib.org/. Support for public key algorithms will be unavailable.所以我们需要下载6.0版本后的:// 这里我只找到了官网的https版本,没办法,只好本地下载,然后rz到服务器,因为是二进制文件,要带上-be参数rz -be// 然后正常编译$ ./configure & make & make install…Libraries have been installed in: /usr/local/libIf you ever happen to want to link against installed librariesin a given directory, LIBDIR, you must either use libtool, andspecify the full pathname of the library, or use the ‘-LLIBDIR’flag during linking and do at least one of the following: - add LIBDIR to the ‘LD_LIBRARY_PATH’ environment variable during execution - add LIBDIR to the ‘LD_RUN_PATH’ environment variable during linking - use the ‘-Wl,-rpath -Wl,LIBDIR’ linker flag - have your system administrator add LIBDIR to ‘/etc/ld.so.conf’这里提醒我们需要将动态库链接到缓存中,我们采用第四种方案,可以参考ldconfig命令:$ vim /etc/ld.so.conf// 添上安装的.so文件路径/usr/local/lib:wq$ ldconfig$ ldconfig -v | grep gmp libgmp.so.10 -> libgmp.so.10.3.2 libgmpxx.so.4 -> libgmpxx.so.4.1.0 libgmp.so.3 -> libgmp.so.3.5.0看到libgmp.so.10就是我们安装的最新版本,现在OK了。然后重新编译安装nettle,会生成libhogweed.so文件:$ ll | grep weed-rw-r–r– 1 root root 541 Dec 12 22:12 hogweed.pc-rw-r–r– 1 work work 590 Nov 19 2017 hogweed.pc.in-rw-r–r– 1 root root 6154192 Dec 12 22:13 libhogweed.a-rw-r–r– 1 root root 298 Dec 12 22:12 libhogweed.map-rw-r–r– 1 work work 338 Nov 19 2017 libhogweed.map.in-rwxr-xr-x 1 root root 5519996 Dec 12 22:13 libhogweed.so-rw-r–r– 1 root root 8 Dec 12 22:13 libhogweed.stamp请注意如果安装完成后,如果出现多个版本的gmp库,请删除老版本的。具体删除哪一项请自行斟酌,我删除了所有的,然后在编译的过程中,会报错:can’t find libgmp.so.3,说明libgmp.so.3这个是基础库,请不要动!等我删除了老版本的,重新编译nettle就OK。如果你安装成功了新版本,依然编译不成功,请参考这个。恐怖的依赖地狱用二进制来安装的时候,总是会出现各种各样的问题,缺少各种依赖的包,解决方法就是缺什么就去安什么,但是会非常恐怖。为了解决nettle安装的问题,除了上面的gmp,我还安装了最新版本的各种库:libunistring: https://www.gnu.org/software/...p11-kit:https://github.com/p11-glue/p…libffi:https://sourceware.org/libffi/pkg-config: https://pkg-config.freedeskto...libtasn1: https://ftp.gnu.org/gnu/libta…同时,由于gnutls编译不通过的问题,又升级了pkg-config,它依赖于Libtasn1。继续安装gnutls库(失败、暂时放弃更新)./configure// 此时没有错误信息了,但是还有很多WARNING信息*** autogen not found. Will not link against libopts.*** You will not be able to create source packages with ‘make dist’ because gtk-doc >= 1.14 is not found.*** LIBIDN2 was not found. You will not be able to use IDN2008 support*** libunbound was not found. Libdane will not be built.*** trousers was not found. TPM support will be disabled.*** `guile-snarf’ from Guile not found. Guile bindings not built.*** The DNSSEC root key file in /etc/unbound/root.key was not found.*** This file is needed for the verification of DNSSEC responses.*** Use the command: unbound-anchor -a “/etc/unbound/root.key”*** to generate or update it.// 继续编译,又报错了make…tlsproxy/buffer.c:40: error: redefinition of typedef ‘buffer_t’tlsproxy/buffer.h:31: note: previous declaration of ‘buffer_t’ was here暂时放弃更新wget,过几天继续尝试,解决各种问题太费时间了如果想要减少warning信息,可以更新autogen等库:autogen: https://ftp.gnu.org/gnu/autog...guile: http://alpha.gnu.org/gnu/guile/gcc: http://ftp.tsukuba.wide.ad.jp...mpc: https://ftp.gnu.org/gnu/mpc/安装autogen过程中需要依赖guile,然而安装guile时又报错:guile configure: error: Cannot find a type to use in place of socklen_t放弃更新autogen。尝试curl更新,层层依赖,放弃$ curl https://dev.mysql.com/downloads/file/?id=480751curl: (35) SSL connect error根据报错原因和网上资料是由于版本过老,需要更新curl版本。从官方地址下载curl后安装,再次用新版本的curl请求:$ curl https://dev.mysql.com/downloads/file/?id=480751curl: (35) error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure还是报错,根据上面的资料,如果依然不能解决问题,需要更新NSS,NSS和OpenSSl类似,都属于底层密码学,由Mozilla维护,MDN文档提供安装说明,它跟前面的二进制文件略有不同,不提供configure自动配置,详细的查看它的文档。安装NSS库比较麻烦,还需要再安装GYP库,想起来又是层层嵌套的依赖关系,放弃更新。解决方案:本地下载,rz上传在耗费两天的时间后,我及时的终止了无畏的尝试,转而使用本地下载mysql8.0文件,然后rz -be上传到服务器,搞定。结论:Linux上层层依赖的二进制文件安装简直是地狱版的体验,在给我们带来高自由度的同时也有无尽的烦恼,然而yum安装版本又过低,不能满足需求。虽然最终还是没有成功更新wget或者curl,但是在整个过程中,也学习到了很多的新东西,在这篇文章总结一下过程,希望也能帮助一些人在某一步骤遇到的问题。解决问题整体思路和过程参考资料mysql8.0官网下载地址:https://dev.mysql.com/downloa…Mysql三种安装方式详解:https://www.jianshu.com/p/a04…[StackOverFlow] wget ssl alert handshake failure:https://stackoverflow.com/que…卸载二进制程序:http://www.blogjava.net/zhyiw…wget下载地址:http://mirror.sergal.org/gnu/…gnutls下载地址:http://www.ring.gr.jp/pub/net…利用.sig文件验证数据的完整性:https://blog.csdn.net/xiazhiy…下载安装nettle http://www.linuxfromscratch.o...nettle官方文档:http://www.lysator.liu.se/~ni…gmp下载地址:https://gmplib.org/ldconfig命令:http://man.linuxde.net/ldconfigSecureCRT rz 上传文件失败问题:https://blog.csdn.net/heavend…初识NSS,一文了解全貌:https://cloud.tencent.com/dev…MDN文档 NSS:https://developer.mozilla.org…curl: (35) SSL connect error:https://stackoverflow.com/que…简述configure、pkg-config、pkg_config_path三者的关系:http://www.mike.org.cn/articl…How to compile GnuTLS: https://stackoverflow.com/que… ...

December 13, 2018 · 6 min · jiezi

同一个系统内使用curl模拟post请求如何不被csrf拦截方案

关于csrf的原理和在yii2内的运行建议先看之前发的一篇文 https://nai8.me/article/383本篇我们要做一个事情,就是在同一个yii2应用中,某个action使用curl模拟表单提交到另一个action,但是你我都知道在yii2内如果发送post请求,需要经过csrf验证,那么使用curl模拟的时候如何通过csrf那?我们来实现。模拟POST在这里我使用yii2官方的http客户端扩展,模拟一个post请求很简单,如下代码。$client = new Client([ ’transport’ => ‘yii\httpclient\CurlTransport’,]);$response = $client->createRequest() ->setMethod(‘POST’) ->setUrl(‘https://xxx.com/demo/csrf-post.html') ->setData([ ‘username’=>‘abei2017’, ‘_csrf’=>Yii::$app->request->getCsrfToken() ])->send();echo $response->getContent();以上使我们最先想到的,提交一组数据到某个url,但是这样并不能得到预想的结果。原因之所以被yii2的csrf拦截,主要是因为使用curl模拟POST请求的时候没有奖cookie中的 _csrf 也一起发送给服务器端。这个cookie值将用于csrf的具体验证工作,那就简单了。$client = new Client([ ’transport’ => ‘yii\httpclient\CurlTransport’,]);$response = $client->createRequest() ->setMethod(‘POST’) ->setUrl(‘https://xxx.com/demo/csrf-post.html') ->setCookies([ [’name’ => ‘_csrf’, ‘value’ => urlencode($_COOKIE[’_csrf’])], ]) ->setData([ ‘username’=>‘abei2017’, ‘_csrf’=>Yii::$app->request->getCsrfToken() ])->send();echo $response->getContent();ok,之所以没有使用yii2内置的cookie功能,主要是因为yii2在设置cookie的时候默认是进行加密的,而获取时候会自动解密。如果使用yii2内置cookie组件获取,则获取是解密后的,再用来模拟就会出问题,我们需要使用curl发送一个经过加密的cookie。当然如果你也可以配置yii2文件将cookie的加密解密去掉。大功告成。

September 26, 2018 · 1 min · jiezi