VBS模拟Post上传文件失败

目的:通过VBS上传本地的文件到服务端。
服务端接受文件:upload_file.php
图形操作界面:upload.php
通过Wireshark抓包看到:VBS模拟Post的数据包和通过IE手工发送完全一样,但是服务器端就是不认,哪个地方出错了呢?代码如下:

VBScript code:

'''客户端文件upload.vbs
Dim objFile,fileContent
Set objFile = CreateObject("Adodb.Stream") 
objFile.Type = 2
objFile.Charset = "gb2312"
objFile.Open
objFile.LoadFromFile "C:\test.txt" 
Do While Not objFile.EOS 
    fileContent = fileContent & objFile.ReadText
Loop
objFile.Close

s = s & "-----------------------------7da2612fbe0662" 
s = s & Chr(13) & Chr(10) 
s = s & "Content-Disposition: form-data; name=" & Chr(34) & "file" & Chr(34) & "; filename=" & Chr(34) & "test.txt" & Chr(34) 
s = s & Chr(13) & Chr(10) 
s = s & "Content-Type: text/plain" 
s = s & Chr(13) & Chr(10)
s = s & Chr(13) & Chr(10)

s = s & read

s = s & Chr(13) & Chr(10) 
s = s & "-----------------------------7da2612fbe0662" 
s = s & Chr(13) & Chr(10)

s = s & "Content-Disposition: form-data; name=" & Chr(34) & "submit" & Chr(34)
s = s & Chr(13) & Chr(10)
s = s & Chr(13) & Chr(10)
s = s & "Submit"
s = s & Chr(13) & Chr(10)
s = s & "-----------------------------7da2612fbe0662--"
s = s & Chr(13) & Chr(10)

Dim xmlhttp
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
'Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "POST", "http://192.168.0.10:8080/upload_file.php", False 

xmlhttp.setRequestHeader "Content-Type", "multipart/form-data; boundary=-----------------------------7da2612fbe0662"
'xmlhttp.setRequestHeader "User-Agent", "Microsoft.XMLHTTP"
'xmlhttp.setRequestHeader "Referer", "http://192.168.0.10:8080/upload.php"
'xmlhttp.setRequestHeader "Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"

xmlhttp.send s
WScript.Echo xmlhttp.responseText
Set objFile = Nothing
Set xmlhttp = Nothing

服务端:upload.php
HTML code:

enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

服务端:upload_file.php
PHP code:

<?php
var_dump($_FILES);
?>

vbs上传数据包:
HTML code:

POST /upload_file.php HTTP/1.1

Accept: */*

Accept-Language: zh-cn

Content-Type: multipart/form-data; boundary=-----------------------------7da2612fbe0662

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; QQDownload 667; TencentTraveler 4.0)

Host: 192.168.0.10:8080

Content-Length: 294

Connection: Keep-Alive

Cache-Control: no-cache

-----------------------------7da2612fbe0662

Content-Disposition: form-data; name="file"; filename="test.txt"

Content-Type: text/plain

ffff

-----------------------------7da2612fbe0662

Content-Disposition: form-data; name="submit"

Submit

-----------------------------7da2612fbe0662--

HTTP/1.1 200 OK

Content-Type: text/html

Server: Microsoft-IIS/6.0

X-Powered-By: PHP/5.1.2

X-Powered-By: ASP.NET

Date: Mon, 27 Dec 2010 16:24:10 GMT

Connection: close

array(0) {
}
array(0) {
}
Upload: <br />Type: <br />Size: 0 Kb<br />Temp file: <br />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值