Visual Basic 6.0 - WinHttp

sample PLD Upload using WinHttp API:
Private Sub pld0200upload()

'build pld0200 request message


'pld0200 request message part 1
Dim msgPart1 As String
msgPart1 = "AppVersion=1.0&AcceptUPSLicenseAgreement=YES&ResponseType=application/x-ups-pld&VersionNumber=V4R1&UserId=PLDDSTEST&Password=PLDDSTEST"

'pld0200 request message part 1 include header
msgPart1 = "Content-type: application/x-www-form-urlencoded" & vbCrLf & _
           "Content-length: " & Len(msgPart1) & vbCrLf & vbCrLf & _
           msgPart1


'pld0200 request message part 2
Dim pld0200file As String
Open "c:\temp\[filename]" For Binary Access Read As #1          'open pld0200file
 Input #1, pld0200file                                          'read pld0200file
Close #1                                                        'close pld0200file

'pld0200 request message part 2 include header
Dim msgPart2 As String
msgPart2 = "Content-type: application/x-ups-binary" & vbCrLf & _
           "Content-length: " & Len(pld0200file) & vbCrLf & vbCrLf & _
           pld0200file


'build complete pld0200request message
Dim PLD0200Request As String
PLD0200Request = "--BOUNDARY" & vbCrLf & _
                 msgPart1 & vbCrLf & vbCrLf & _
                 "--BOUNDARY" & vbCrLf & _
                 msgPart2 & vbCrLf & vbCrLf & _
                 "--BOUNDARY--"



'create a WinHttp Object
Dim myWinHTTP As WinHttp.WinHttpRequest
Set myWinHTTP = New WinHttp.WinHttpRequest


'Opens an HTTP connection 
'Parameters:
'1st: POST = methode used for PLD Upload
'2nd: https://www.pld-certify.ups.com/hapld/tos/kdwhapltos = Server url
'3rd.: false = Opens the HTTP connection in synchronous mode,
             so a call to Send does not return until WinHTTP has completely received the response.
myWinHTTP.Open "POST", "https://www.pld-certify.ups.com/hapld/tos/kdwhapltos", False


'set an HTTP request header.
'multipart/mixed; boundary=BOUNDARY" is the required Content-Type for the PLD upload
myWinHTTP.SetRequestHeader "Content-Type", "multipart/mixed; boundary=BOUNDARY"


'Sends an HTTP request to an HTTP server.
'Parameters: Message to send
myWinHTTP.Send Text1.Text


'Gets all HTTP response headers
'not required for the upload , but helpful for error tracing'
dim responseHeader as String
responseHeader = myWinHTTP.GetAllResponseHeaders


'Retrieves the response entity body as a String
dim responseText as String
responseText = myWinHttp.ResponseText


'insert here the code for parsing the response

End Sub
Note: In a production environment it is recommend adding also some code for error handling



Copyright © 2003 United Parcel Service Deutschland Inc. & Co. OHG