Bash 即使状态代码为400,如何从curl请求获得文件输出?

Bash 即使状态代码为400,如何从curl请求获得文件输出?,bash,shell,curl,Bash,Shell,Curl,如果我通过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:

如果我通过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,33551,34324,34904,35055,35091,36604,36683,36716,36946,37017,37055,37126",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...
HTTP/1.1200正常
日期:2012年2月29日星期三格林尼治标准时间16:49:09
过期:-1
缓存控制:专用,最大年龄=0
内容类型:text/html;字符集=ISO-8859-1
设置Cookie:PREF=ID=16ad7441d475580e:FF=0:TM=1330534149:LM=1330534149:S=2MpGe04BWQ8Kn3P7;expires=2014年2月28日星期五格林威治标准时间16:49:09;路径=/;domain=.google.de
设置Cookie:NID=57=bcgucqnq5dmwcbemp85sadnudxg2_LG4eZFmS-yr1w38uytnub8biiosk274wgjg99ujdw6t8n78d4qzbma7q2emkq69-gCjOysFNLGFggrvMxcqEOl7p1hemeQ;expires=Thu,2012年8月30日格林威治标准时间16:49:09;路径=/;domain=.google.de;HttpOnly
P3P:CP=“这不是P3P策略!请参阅http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 有关详细信息,请参阅。“
服务器:gws
X-XSS-Protection:1;模式=块
X-Frame-Options:SAMEORIGIN
传输编码:分块
Googlewindow.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.location.protocol=“https:”,kEXPI:“317013313434904350535353535353535353535353535353535353535353737373737337126”,si:{e:“31701335513432434904350553509136604366833671636946370173705537126”,ei:“BVdOT7OzE8_ktQaqk-WGDw”},作者:0,
(一、d、f、h)的日志:函数(a、d、f、h)的函数(a、d、f、h)的日志:函数(a、d、f、h)的日志:函数(a、d、f、h)的日志:函数(a、d、f、f、h){var=新图像,g=谷歌,k=g=g=谷歌,k=g=g.C.lc,g=g=谷歌,k=g=g.C.lc,g=g.C,g=谷歌,g=g.L,g.C,g.lc,i,i,i,i=g.L,i=g.L,i=g.L,i=g.L,i=g.L,i,i,i=g.L,i=g.L,i=g.L,i=g.L,i=g.L,i,i=g.L,i=g.L,i=g.L,i,i.L,i/^http:/i;如果(b)测试(j)&&https(){google.ml(新错误(“GLMM”),false,{src:j});
删除k[i];返回}e.src=j;g.li=i。。。
当我对url执行相同的请求时,响应的状态代码为400,我将得到一个错误,提示shell,文件将为空:

curl-ishttps://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 >临时文本文件

如果我得到一个状态代码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"}