|
Public Sub UploadRap()
Dim strPost
As String
Dim objHTTP, replyTXT As String
Dim AuthenticationTicket
As String
AuthenticationTicket = ""
objHTTP = CreateObject("Msxml2.ServerXMLHTTP")
strPost = "https://technet.rapaport.com/HTTP/Authenticate.aspx"
objHTTP.Open("POST", strPost,
False)
Call objHTTP.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded")
objHTTP.send("Username=username&Password=password")
replyTXT = objHTTP.responseText
If objHTTP.Status = "200" Then
AuthenticationTicket = replyTXT
Else
AuthenticationTicket = ""
End If
Stop
Dim DestURL
As String
DestURL = "http://technet.rapaport.com/HTTP/Upload/Upload.aspx?Method=file"
DestURL = DestURL & "&ticket="
+ AuthenticationTicket
DestURL = DestURL & "&ReplaceAll=true&FirstRowHeaders=true&LotListFormat=Rapnet"
Dim FileName
As String
FileName = "c:\stock.csv"
UploadFile(DestURL, FileName, "Stock")
End Sub
Sub UploadFile(ByVal
DestURL As String, ByVal
FileName As String, _
Optional ByVal FieldName
As String = "File")
Dim sFormData As String, D As String
Stop
Const Boundary As String = "---------------------------0123456789012"
sFormData = GetFile(FileName)
D = "--" & Boundary & vbCrLf
D = D & "Content-Disposition: form-data;
name=""" & FieldName & """;"
D = D & " filename=""" & FileName &
"""" & vbCrLf
D = D & "Content-Type: application/upload" & vbCrLf & vbCrLf
D = D & sFormData
D = D & vbCrLf & "--" & Boundary
& "--" & vbCrLf
IEPostStringRequest(DestURL, D, Boundary)
End Sub
Sub IEPostStringRequest(ByVal
URL As String, ByVal
FormData As String, ByVal
Boundary As String)
Dim WebBrowser : WebBrowser
= CreateObject("InternetExplorer.Application")
WebBrowser.Visible = True
Dim bFormData()
As Byte
ReDim bFormData(Len(FormData)
- 1)
bFormData = StrConv(FormData, vbFromUnicode)
WebBrowser.Navigate(URL, , , bFormData, _
"Content-Type: multipart/form-data;
boundary=" & Boundary & vbCrLf)
Do While WebBrowser.Busy
DoEvents()
Loop
WebBrowser.Quit()
End Sub
Function GetFile(ByVal
FileName As String) As String
Dim FileContents() As Byte, FileNumber As Integer
ReDim FileContents(FileLen(FileName)
- 1)
FileNumber = FreeFile()
Open FileName
For Binary As FileNumber
Get FileNumber, , FileContents
Close(FileNumber)
GetFile = StrConv(FileContents, vbUnicode)
End Function
|
|