Писал и раньше, советовали по сабжу перейи на винсок для создания полного ШТТП запроса. сделал, все ГЕТ- переменные передаються без проблем, но вот сам файл почему то нет.
Option Explicit
Const SockHost = "localhost"
Const SockPort = 80
Const SockUrl = "/getfile.php?value1=Hello&value2=World&value3=999090&slots=1"
Private Sub Command1_Click()
Sock.Close
Sock.Connect SockHost, SockPort
End Sub
Private Sub Sock_Connect()
Dim Buf As String
Dim Tmp() As Byte
Buf = _
"POST " & SockUrl & " HTTP/1.0" & vbNewLine & _
"Content-Type: multipart/form-data; boundary=---------------------------7d4a98d0442" & vbNewLine & _
"Host: " & SockHost & vbNewLine & vbNewLine & _
"-----------------------------7d4a98d0442" & vbNewLine & _
"Content-Disposition: form-data; name=""upload1""; filename=""E:\2.jpg""" & vbNewLine & _
"Content-Type: image/pjpeg" & vbNewLine & vbNewLine & _
FileGetContents("e:\1.jpg") & vbNewLine & _
"-----------------------------7d4a98d0442--"
ReDim Tmp(Len(Buf))
Tmp = StrConv(Buf, vbFromUnicode)
Sock.SendData Tmp
'Text1.Text = Buf
End Sub
Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
Dim Buf As String
Sock.GetData Buf, vbString, bytesTotal
Text1.Text = Buf
Sock.Close
End Sub
Private Sub Sock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Connection error: " & Description, vbCritical, "Connection error"
End Sub
Private Function FileGetContents(strFilePath)
Dim Buf As String
Dim F As Integer
F = FreeFile
On Error GoTo ErrorHandler
Open strFilePath For Binary As F
Buf = String(LOF(F), " ")
Get #F, , Buf
Close #F
FileGetContents = Buf
Exit Function
ErrorHandler:
MsgBox "File erorr: " & Err.Description, vbCritical, "File error"
End Function
Ответить
|