vb 调用wininet HttpSendRequest 上传图片数据 数据参数问题
Private Declare Function HttpSendRequest Lib "wininet.dll" _Alias "HttpSendRequestA" _
(ByVal hHttpRequest As Long, _
ByVal sHeaders As String, _
ByVal lHeadersLength As Long, _
ByVal sOptional As String, _
ByVal lOptionalLength As Long) As Boolean
我想用他来上传图片 但是第三个参数 换成其他类型就崩溃 或者报错 我把图片数据由字节数组转换成字符再上传总是丢失数据 上传的数据不全 不知道用什么方法好 能不能指导一下 重谢!
postdatherd = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""file""; filename=""C:\123.jpg""" & vbCrLf & "Content-Type: image/image/pjpeg" & vbCrLf & vbCrLf
'这里是图片数据部分
a = vbCrLf & "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""user""" & vbCrLf & vbCrLf & "xinlen" & vbCrLf
b = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""pw""" & vbCrLf & vbCrLf & "000000" & vbCrLf
c = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""tid""" & vbCrLf & vbCrLf & "1001" & vbCrLf
d = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""yxj""" & vbCrLf & vbCrLf & "1" & vbCrLf
e = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""xtime""" & vbCrLf & vbCrLf & "12" & vbCrLf
f = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""bz""" & vbCrLf & vbCrLf & "chajiances" & vbCrLf
g = "-----------------------------7dcbb234f096e" & vbCrLf & "Content-Disposition: form-data; name=""submit""" & vbCrLf & vbCrLf & "上传" & vbCrLf
h = "-----------------------------7dcbb234f096e--"
g = a & b & c & d & e & f & g & h
aa = StrConv(postdatherd, vbFromUnicode)
an = (UBound(aa) + 1) '图片头先放进去
Dim filenumber As Long
Dim filelen As Long
filenumber = FreeFile
Open "f:\123.jpg" For Binary As #filenumber
filelen = LOF(filenumber)
MsgBox (LOF(filenumber))
ReDim cc(filelen - 1) As Byte
Get #filenumber, , cc() '图片数据先放 cc数组
Close filenumber
cn = (UBound(cc) - LBound(cc) + 1) '图片数据由cc数组转移到aa加入到后面
ReDim Preserve aa(UBound(aa) + cn) As Byte
For i = 0 To cn - 1
aa(an + i) = cc(i)
Next
an = (UBound(aa) - LBound(aa) + 1)
MsgBox "集合图片后" & an
cc = StrConv(g, vbFromUnicode) '继续添加后面的数据
cn = (UBound(cc) - LBound(cc) + 1)
ReDim Preserve aa(UBound(aa) + cn)
For i = 0 To cn - 1
aa(an + i) = cc(i)
Next
an = (UBound(aa) - LBound(aa) + 1)
zhenjia = HttpSendRequest(inethttpjb, sheader, Len(sheader) - 1, aa, (UBound(aa) - LBound(aa) + 1))
我想用他来上传图片 但是第三个参数 换成其他类型就崩溃 或者报错 我把图片数据由字节数组转换成字符再上传总是丢失数据 上传的数据不全 不知道用什么方法好 能不能指导一下 重谢!
--------------------编程问答-------------------- 用XML方式的我会
需要写什么软件可以找我qq:2605961812 --------------------编程问答-------------------- HttpSendRequest函数,我发过贴子的。
如果是发送二进制数据,需要改一个参数的类型。
补充:VB , 网络编程