【结帖】winhttp服务器返回头信息不规则导致报错:服务器返回的信息无效或不可识别
本帖最后由 cihron 于 2017-7-4 09:47 编辑在使用以下代码向服务器发送POST请求后,收不到任何信息,包括状态码和状态描述 $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; 捕获错误信息
Global $_HTTP = ObjCreate("winhttp.winhttprequest.5.1")
$url = 'http://www.XXXXXXXX.com/do.action'
$dat = 'key=&validateSelect=1'
$_HTTP.open( 'POST', $url )
$_HTTP.setRequestHeader( 'x-requested-with', 'XMLHttpRequest' )
$_HTTP.setRequestHeader( 'Accept-Language', 'zh-CN' )
$_HTTP.setRequestHeader( 'Accept', '*/*' )
$_HTTP.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' )
$_HTTP.setRequestHeader( 'User-Agent', 'Mozilla/4.0 ' )
$_HTTP.setRequestHeader( 'Host', 'www.XXXXXXXX.com/do.action' )
$_HTTP.setRequestHeader( 'Content-Length', '21' )
$_HTTP.setRequestHeader( 'DNT', '1' )
$_HTTP.setRequestHeader( 'Proxy-Connection', 'Keep-Alive' )
$_HTTP.setRequestHeader( 'Pragma', 'no-cache' )
$_HTTP.send( $dat )
$sResponseHeader = BinaryToString( $_HTTP.getAllResponseHeaders(), 4 )
$sResponseBody = BinaryToString( $_HTTP.responseBody, 4 )
MsgBox( 0, $_HTTP.Status & " - " & $_HTTP.StatusText, $sResponseHeader & @CRLF & $sResponseBody )
Func MyErrFunc() ; 捕获错误信息
Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF& @CRLF & _
"err.description is: " & @TAB & $oMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: " & @TAB & hex($oMyError.number,8)& @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.helpcontext _
)
Local $err = $oMyError.number
If $err = 0 Then $err = -1
$g_eventerror = $err; to check for after this function returns
Endfunc
MessageBox显示内容为空
err.windescription 报错:服务器返回的信息无效或不可识别
浏览器捕获的响应头文件为:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Sun, 28 May 2017 04:53:54 GMT
Pragma: No-cache
Pragma: no-cache
Content-Type: text/plain;charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
SET-COOKIE: JSESSIONID=bvtNZhwKbzCtVoU-tHF718wbU2b04eszAR9R24CDzm7kNhZXKKR2!1189723176!1495947156490;path=/uac;HttpOnly
SET-COOKIE: CSRF_VALIDATE=b0d7f5f9b3530f086c0c2830966c4345;path=/uac/;HttpOnly
Set-Cookie: AIPortal_Oper_LastAccessedTime=MTQ5NTk0NzIzNDMxOA==;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATLastAccessedTime=31343935393437323334333138;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Main_Account=Y2hpeWluZ3lpbmc=;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Main_OpName=s9jTr9Ov;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Main_OrgId=MjE3NDA0;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Main_OrgName=1eO9rVzOwtbdXMDWx+VcwNazycf40/K+rdOqsr9czsLW3cPAwNbBrMv4UDAwMrXqKMDWx+XA1rPJ
KQ==;path=/;domain=chnl.zj.chinamobile.com;HttpOnly: ; 这行数据明显有问题,貌似不小心从中间折行了,问题应该就在这里
Set-Cookie: AIPortal_Main_Email=MTM5Njc3NzAxMzFAMTM5LmNvbQ==;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Main_SessId=r2rjtyt39s5wwjizv5achhuhcvrbhk32;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATHostIp=31302e37382e3230322e3238;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATPort=383030312f756163;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATResAccount=6e756c6c;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATResKey=6e756c6c;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATMainAccount=63686979696e6779696e67;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_HostIp=MTAuNzguMjAyLjI4;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Port=ODAwMS91YWM=;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: AIPortal_Oper_ActiveUrl=aHR0cDovLzRhc3NvY20uY2hubC56ai5jaGluYW1vYmlsZS5jb20vdWFj;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: TOMCATOperActiveUrl=687474703a2f2f346173736f636d2e63686e6c2e7a6a2e6368696e616d6f62696c652e636f6d2f756163;path=/;domain=chnl.zj.chinamobile.com;HttpOnly
Set-Cookie: JSESSIONID=Rh9NZ0vASEyPrqr2BtE5RGGTYL_5LIz3WM7S7WoppaPHLNbqSC1W!1189723176; path=/uac; HttpOnly
Connection: Keep-alive
Via: 1.1 ID-0002262071213050 uproxy-13
Content-Length: 1
Y
初步怀疑是由于 响应头不规范造成的错误,有什么方法解决这个问题呢?? 你这一会$_HTTP,一会$_HTTP_OBJECT,你确定你引用的是同一个对象 回复 2# kevinch
不好意思,确定是一个对象,编辑时出点小差错。 你发的是 Response, 那 Request 数据呢 回复 4# 1361739590
Global $_HTTP = ObjCreate("winhttp.winhttprequest.5.1")
$url = 'http://www.XXXXXXXX.com/do.action'
$dat = 'key=&validateSelect=1'
$_HTTP.open( 'POST', $url )
$_HTTP.setRequestHeader( 'x-requested-with', 'XMLHttpRequest' )
$_HTTP.setRequestHeader( 'Accept-Language', 'zh-CN' )
$_HTTP.setRequestHeader( 'Accept', '*/*' )
$_HTTP.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' )
$_HTTP.setRequestHeader( 'User-Agent', 'Mozilla/4.0 ' )
$_HTTP.setRequestHeader( 'Host', 'www.XXXXXXXX.com/do.action' )
$_HTTP.setRequestHeader( 'Content-Length', '21' )
$_HTTP.setRequestHeader( 'DNT', '1' )
$_HTTP.setRequestHeader( 'Proxy-Connection', 'Keep-Alive' )
$_HTTP.setRequestHeader( 'Pragma', 'no-cache' )
$_HTTP.send( $dat )
这就是 request 数据。
在实际环境中这是一个短信验证页面,当我把验证码输的时候,就不存在这个问题了,因为返回头不一样。如果输入正确,就会出现这种情况。
所以我感觉应该是这个返回头的原因。 说实话不懂你的意思。 回复 6# 1361739590
应该是响应报文头格式异常导致的错误,有点诡异 回复 6# 1361739590
有空的话,我发你测试代码,你看下 地址没有,不好测试
建议你用抓包软件抓个post包看看,发送的信息和你自己编写的发送信息是不是一致
页:
[1]