感谢DRUNK,真弯路了,最后以POST上传方式解决!
Global $ScanFile = FileOpenDialog("open",@WindowsDir & "\", " 所有文件 (*.*)", 1)
;MsgBox(0,"打开文件为",$ScanFile)
;Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
Global $oHTTP = ObjCreate("MSXML2.XMLHTTP")
;$oHTTP.Option(0) = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
Local $boundary = MakeBoundary();上传分隔线
Local $binhead = $boundary & @CRLF & _
'Content-Disposition: form-data; name="Filedata"; filename="' & $ScanFile & '"' & @CRLF & _
'Content-Type: application/octet-stream' & @CRLF & @CRLF
$binhead = StringToBinary($binhead);二进制
Local $hopen = FileOpen($ScanFile,16);二进制读取文件
If $hopen = -1 Then
MsgBox(4096, "错误", "不能打开文件.")
Exit
EndIf
Local $binbody = FileRead($hopen)
FileClose($hopen)
Local $binfoot = @CRLF & $boundary & @CRLF & _
'Content-Disposition: form-data; name="folder"' & @CRLF & @CRLF & _
'/uploads' & @CRLF & _
$boundary & '--' & @CRLF ;最前的换行别忘了,"--"表示结束符
$binfoot = StringToBinary($binfoot);二进制
Local $bindata, $upurl
$binsend = $binhead & $binbody & $binfoot
;MsgBox(0,"send文件为",$binsend)
$oHTTP.Open("POST", "http://127.0.0.1/uploadify.php", False)
;$oHTTP.setRequestHeader("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, application/msword, application/vnd.ms-excel, vnd.ms-powerpoint, */*")
$oHTTP.setRequestHeader("Content-Type", "multipart/form-data; boundary=" & StringTrimLeft($boundary, 2))
$oHTTP.Send($binsend)
MsgBox(0,"将响应信息作为字符串返回",$oHTTP.responsetext) ;显示登录后返回的响应(字符串形式)
MsgBox(0,"获取响应的所有http头",$oHTTP.getAllResponseHeaders()) ;显示登录后返回的响应头
Func MakeBoundary()
;7d为IE特殊标记,其他未细究
Local $bou = '-----------------------------7dc3b00000000a'
Local $rn = Random(11111111,99999999,1)
$bou = StringReplace($bou, '00000000', $rn)
Return $bou
EndFunc |