加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 即使状态代码为400,如何从curl请求输出到文件?

发布时间:2020-12-16 01:08:02 所属栏目:安全 来源:网络整理
导读:如果我通过curl向普通网站发出请求,我可以将输出定向到带有标题数据的文件,如下所示: 命令: curl -is www.google.de temp.txt 输出: HTTP/1.1 200 OKDate: Wed,29 Feb 2012 16:49:09 GMTExpires: -1Cache-Control: private,max-age=0Content-Type: text/h
如果我通过curl向普通网站发出请求,我可以将输出定向到带有标题数据的文件,如下所示:

命令:

curl -is www.google.de > temp.txt

输出:

HTTP/1.1 200 OK
Date: Wed,29 Feb 2012 16:49:09 GMT
Expires: -1
Cache-Control: private,max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=16ad7441d475580e:FF=0:TM=1330534149:LM=1330534149:S=2MpGe04BWQ8Kn3P7; expires=Fri,28-Feb-2014 16:49:09 GMT; path=/; domain=.google.de
Set-Cookie: NID=57=BCgUcqNQU5dMWcBEMP85saDNUdXg2_LG4eZFmS-yr1W38UyTNuB8BU8iiOOsK2747WGJG99uJDW6t8N78D4QzBma7q2EmKQ69-gCjOysFNLGFggrvMxcqEOl7p1hemeQ; expires=Thu,30-Aug-2012 16:49:09 GMT; path=/; domain=.google.de; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked

<!doctype html><html itemscope itemtype="http://schema.org/WebPage"><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><meta itemprop="image" content="/images/google_favicon_128.png"><title>Google</title><script>window.google={kEI:"BVdOT7OzE8_ktQaqk-WGDw",getEI:function(a){var d;while(a&&!(a.getAttribute&&(d=a.getAttribute("eid"))))a=a.parentNode;return d||google.kEI},https:function(){return window.location.protocol=="https:"},kEXPI:"31701,33551,34324,34904,35055,35091,36604,36683,36716,36946,37017,37055,37126",kCSI:{e:"31701,ei:"BVdOT7OzE8_ktQaqk-WGDw"},authuser:0,ml:function(){},kHL:"de",time:function(){return(new Date).getTime()},log:function(a,d,f,h){var e=new Image,g=google,k=g.lc,i=g.li,m="";e.onerror=(e.onload=(e.onabort=function(){delete k[i]}));k[i]=e;if(!f&&d.search("&ei=")==-1)m="&ei="+google.getEI(h);var j=f||"/gen_204?atyp=i&ct="+a+"&cad="+d+m+"&zx="+google.time(),b=/^http:/i;if(b.test(j)&&google.https()){google.ml(new Error("GLMM"),false,{src:j});
delete k[i];return}e.src=j;g.li=i...

当我对url执行相同的请求时,响应将具有状态代码400,我将收到一个错误,该错误将提示给shell并且文件将为空:

curl -is https://foursquare.com/oauth2/access_token?grant_type=authorization_codeu0026amp;client_id=SOME_CLIENT_IDu0026amp;client_secret=SOME_CLIENT_SECRETu0026amp;code=notavalidcodeu0026amp;redirect_uri=SOME_REDIRECT_URIu0026gt; TEMP.TXT

如果我获得状态代码400,是否有办法将结果提示给文件?

用“包裹”网址
kent$ curl -is "https://foursquare.com/oauth2/access_token?grant_type=authorization_code&client_id=SOME_CLIENT_ID&client_secret=SOME_CLIENT_SECRET&code=notavalidcode&redirect_uri=SOME_REDIRECT_URI" > temp.txt

kent$ cat temp.txt 
HTTP/1.0 200 Connection established


HTTP/1.1 400 Bad Request
Cache-Control: no-cache,private,no-store
Content-Type: application/json; charset=utf-8
Date: Wed,29 Feb 2012 16:59:16 GMT
Expires: Wed,29 Feb 2012 16:59:16 GMT
Pragma: no-cache
Server: nginx/0.8.52
Content-Length: 26
Connection: keep-alive

{"error":"invalid_client"}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读