curlcurl是一个常用的命令行工具,用于请求Web服务器。它的名字意思是客户端URL工具。curl非常强大,它的命令可以在postman中直接使用,postman也支持curl的request方式。常用的结果参数curl有很多参数,这里只列举几个常用的,如果遇到复杂的情况可以参考文档。不知道还有没有朋友不知道postman直接支持curl命令。点击postman中的代码,会出现请求对应的curl命令。-X参数指定HTTP请求的方法。-H参数将标头添加到HTTP请求。-d参数用于发送POST请求的数据体。使用-d参数后,HTTP请求会自动添加headerContent-Type:application/x-www-form-urlencoded。并且会自动将请求转为POST方式,所以可以省略-XPOST-b参数,将cookie发送给服务器。如果想了解更多的参数,可以去看阮一峰老师的文档https://www.ruanyifeng.com/blog/2019/09/curl-reference.html在curl项目中的应用如果你熟悉curl,可以完全替代postman等工具,小伙伴可以直接模拟请求。(我觉得curl看懂常用命令就够了)因为在BFF项目中,往往前端参与开发,我们也会直接调用后端接口。cookie有问题,不方便查找问题和调试。在本地环境中,我们会直接打印出完整的curl请求。这时候可以直接看到报错。开发者只需要知道curl的一些参数,也可以直接使用curl命令复制到postman进行调试。看下工具实体部分代码//只在本地环境输出if(ctx.app.config.env==='local'){conststr=curlString(url,{method,headers,body,})+'\n';console.log('\x1b[32m%s\x1b[0m',str);}/***Buildsacurlcommandandreturnsthestring.*@param{String}urlEndpoint*@param{Object}optionsObjectwithheaders,etc.(fetchformat)*@return{String}cURLcommand*/functioncurlString(url,options){constmethod=options&&options.method&&typeofoptions.method==='string'?options.method.toUpperCase():'GET';consthasHeaders=选项&&options.headers&&typeofoptions.headers==='object';consthasBody=options&&options.body;letcurl=`\ncurl--request${method}\\\n--url'${url}'`;if(hasHeaders){curl+='\\\n'+Object.entries(options.headers).filter(([key,value])=>value!==undefined).map(([key,value])=>`--header'${key}:${value}'`).join('\\\n');}if(hasBody){curl+=`\\\n--data'${bodyToDataString(options)}'`;}returncurl;}/***Constructsbodystringforuseinside--data*@param{Object}optionsObjectwithheaders,etc.(fetchformat)*@return{String}cURLcommanddatastring*/functionbodyToDataString(options){letparsedData;try{parsedData=JSON.parse(options.body);}catch(e){//fallbacktooriginalbodyifitcouldnotbeparsedasJSONparsedData=options.body;}//returnanampersanddelimitedstringconstheaders=_.get(options,'headers');constcontentType=_.toLower(_.get(headers,'content-type')||_.get(headers,'Content-Type'));if(contentType==='application/x-www-form-urlencoded'){if(typeofparsedData==='string'){returnparsedData;}else{returnObject.entries(parsedData).map(([key,val])=>`${key}=${val}`).join('&');}}else{returnJSON.stringify(parsedData);}}vim中的基本操作和配置在vim中非插入打开文件mode之后,不插入编辑可以做哪些基本操作G快速移动到文件底部(常用来查看日志)gg快速移动到文件顶部0快速移动到行首$快速移动到行尾:13快速移动到特定行ZZ将光标移动到屏幕中间dd剪切这一行yy复制这一行uUndo(撤消,撤消的缩写)pPaste(p表示粘贴,粘贴)在mac系统中,可以option+click快速移动到想要的位置(也就是Cursor)insert模式提到了多种移动方式,然后结束几个常用的insert命令,我就结束一些常用的简单的i给你dit在当前光标前o快速进入插入模式,导航到下一行编辑esc退出插入模式,网络ping中的
