heavenm 发表于 2010-11-15 22:52:58

怎么自动提交POST+验证码?

http://www.29cy.com/chklogin.asp
想写个自动提交的

验证码自动识别已经做好了
但是POST上去验证码老是不对

shano 发表于 2010-11-16 02:54:27

截包看了一下没啥问题   唯一就是没有Referer应该是这个原因

republican 发表于 2010-11-16 14:34:18

本帖最后由 republican 于 2010-11-16 14:48 编辑

为了保证Connection不断开,把两个_WinHTTP_GetRespond杂糅在一起(虽然是我自己的UDF,但还是懒一下,见谅),如有需要,请自行修改。#include <Array.au3>
#include <WinHttp_GetRespond.au3>
$s_PicFileName=@ScriptDir &"\key2.bmp"
If FileExists($s_PicFileName) Then FileDelete($s_PicFileName)
$MyOpen=_WinHttpOpen()

Local $Request=["$hRequest","$hConnect",$s_PicFileName]                        ;-----该参数与 _DownLoadByResPodn 的参数相对应
_WinHTTP_GetRespond($MyOpen,"http://www.29cy.com/getcode.asp",0 ,-2,0,12000,"","","","_DirectHandle",$Request)
If @error Then MsgBox(0,"",@error)
_WinHttpCloseHandle($MyOpen)

Func _DirectHandle($hRequest,$hConnect,$SaveFile)

        $rDate= _WinHttpReadData($hRequest,2, _WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_CONTENT_LENGTH))

        $Cookies=_WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_SET_COOKIE)
       
       
        $Cookies=StringRegExp($Cookies,"(.*?;)",3)
        $Cookies=$Cookies
;~         MsgBox(0,"",$rContext)
        $File=FileOpen($SaveFile,18)
        FileWrite($File,$rDate)
        FileClose($File)
        _WinHttpCloseHandle($hRequest)
       
;~         Return
       
        Dim $s_GetOcrString = _myConvertOcr($s_PicFileName)
        If $s_GetOcrString = "" Then; 或 If @error Then
                MsgBox(0, "提示", "出现错误")
                Exit
        EndIf


        ;以下是返回结果情况

        ConsoleWrite($s_GetOcrString & @CRLF);显示原串,形如:8(100%)5(100%)8(100%)6(100%)8(100%),括号内为识别情况,100%表示完全匹配

        ;或,不严格的正则,如\d+实际范围是0-100, 如考虑小数点,简单的写法是\d+改为\d+(?:\.\d+)?
        ConsoleWrite(StringRegExpReplace($s_GetOcrString, "\(\d+%\)", "") & @CRLF);

        ;或,不严格的正则,如\d+实际范围是0-100
        ConsoleWrite(StringRegExpReplace($s_GetOcrString, "(\S)\(\d+%\)", "$1") & @CRLF);
       
        $sFlags = Default
       
        $hRequest = _WinHttpOpenRequest($hConnect, "POST", "/chklogin.asp",Default,Default,Default,$sFlags)
        If @error Or $hRequest = 0 Then MsgBox(0,@error,_GetLastError())
        $hTimeOut = 12000
        _WinHttpSetTimeouts($hRequest,$hTimeOut,$hTimeOut,$hTimeOut,$hTimeOut + 5000)
       
        Dim $aOcrString = StringRegExp($s_GetOcrString, "(\S)\(\d+%\)", 3)
        _ArrayDisplay($aOcrString);分解每个字符
        $Context = "title=%C2%CC%C9%AB%D7%D4%D6%FA%C1%B4&leibie=111&qq=320134733&Email=320134733@qq.com&url=http%3A%2F%2Fwww.aqmh.net&logo=&memo=%C2%CC%C9%AB%D7%D4%D6%FA%C1%B4&mofei=" & $aOcrString & $aOcrString & $aOcrString & $aOcrString & "&action=add_wz"
        _WinHttpAddRequestHeaders($hRequest, "Content-Length: "&StringLen($ConText)&@CRLF)
        _WinHttpAddRequestHeaders($hRequest, "Cookie: "&$Cookies&@CRLF)
        _WinHttpAddRequestHeaders($hRequest,"Content-Type: application/x-www-form-urlencoded")
        _WinHttpSendRequest($hRequest)
        If @error Then Return MsgBox(48,2,_GetLastError())
       
        _WinHttpWriteData($hRequest,$Context)
        _WinHttpReceiveResponse($hRequest)
        If Not _WinHttpQueryDataAvailable($hRequest) Then Return MsgBox(48,3,_GetLastError())

        $rDate= _WinHttpReadData($hRequest,2, _WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_CONTENT_LENGTH))
       
        MsgBox(0,"",BinaryToString($rDate))
        FileWrite("test.html",$rDate)
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
EndFunc


Func _myConvertOcr($s_PicFileName, $s_OcrToolPath = @ScriptDir)
        If Not FileExists($s_PicFileName) Then Return SetError(1, 0, "");要转换的图形文件没找到

        If StringRight($s_OcrToolPath, 1) = "\" Then $s_OcrToolPath = StringTrimRight($s_OcrToolPath, 1)

        If (Not FileExists($s_OcrToolPath & "\Convert.ini")) Or (Not FileExists($s_OcrToolPath & "\Ocr.exe")) Then Return SetError(1, 0, "");OCR工具或静默参数设置未找到

        Local $s_IniFile = $s_OcrToolPath & "\Convert.ini" ;由ocr.exe生成的静默参数文件
        IniWrite($s_IniFile, "Setup", "CheckCodeFile", $s_PicFileName)

        #cs
                ;原调用方式
                FileDelete($s_OcrToolPath&"\CheckCode.Txt")
                FileDelete($s_OcrToolPath&"\Error.Log")
                Run($s_OcrToolPath&"\Ocr.exe Convert");原版本未做RunWait改造
                While 1
                If FileExists($s_OcrToolPath&"\CheckCode.Txt") Then Return $s_OcrToolPath&"\CheckCode.Txt"
                If FileExists($s_OcrToolPath&"\Error.Log") Then Return SetError(1, 0, "")
                Sleep(10)
                WEnd
        #ce
        RunWait($s_OcrToolPath & "\Ocr.exe Ocr");
        Select
                Case FileExists($s_OcrToolPath & "\CheckCode.Txt")
                        Return FileRead($s_OcrToolPath & "\CheckCode.Txt");成功返回
                Case Else;或读取$s_OcrToolPath&"\Error.Log"内容做进一步错误分析
                        Return SetError(1, 0, "")
        EndSelect
EndFunc   ;==>_myConvertOcr

heavenm 发表于 2010-12-11 02:42:41

{:face (88):}
相当感谢楼上的,没早发现你的回帖
自己研究了很久!~
页: [1]
查看完整版本: 怎么自动提交POST+验证码?