|
-
Jul 17th, 2012, 11:32 AM
#27
New Member
Re: Winsock: Making HTTP POST/GET Requests
I modified this app a bit to simplify it but I'm getting some errors. When I try the "Send" command button a second time, "Invalid Operation at Current State" error occurs.
I am also having timeout problems sending multiple requests. The service is not recording data sent continuosly, hitting the "send" button. I think it has something to do with Winsock and not the service.
Would someone mind helping me? Thanks!
Option Explicit
' we set this to true whil a connection is established
Private blnConnected As Boolean
Dim Transaction_Num As String
Dim customer As String
Dim Location As String
Dim Weight As String
Dim Sort_Class As String
Dim ppp As Variant
Private Sub cmdSend_Click()
Dim strMethod As String
Dim strData As String
Dim strPostData As String
Dim strHeaders As String
Dim strHTTP As String
Dim X As Integer
Dim tmp As Integer
Dim Transaction_NumInt As Integer
Dim thestring As String
blnConnected = False
strPostData = ""
strHeaders = ""
If blnConnected Then Exit Sub
'"GET
'For all loads: http://ics.etechsystems.com:3000/col..._loads_on_belt (test) or http://192.168.0.21:3000/colmac/current_loads_on_belt (on site)
'To query a single load: http:// ics.etechsystems.com:3000/colmac/get_load/x (test) or http:// 192.168.0.21:3000/colmac/get_load/x (on site)
'For this service the x should be replaced with the tranaction_number you would like to find.
' txtUrl.Text = "http://ics.etechsystems.com:3000/colmac/current_loads_on_belt"
' txtUrl.Text = "http://ics.etechsystems.com:3000/colmac/get_load/1"
'POST
'For posting a load during a Colmac dump on belt: http://ics.etechsystems.com:3000/colmac/new_load on site: http://192.168.0.21:3000/colmac/new_load
' configure winsock
winsock.Protocol = sckTCPProtocol
winsock.RemoteHost = "ics.etechsystems.com"
winsock.RemotePort = 3000
strMethod = "POST"
' build encoded data the data is url encoded in the form
strData = ""
strHTTP = strMethod & " " & "/colmac/new_load" & " HTTP/1.1" & vbCrLf
strHTTP = strHTTP & "Host: " & "ics.etechsystems.com" & vbCrLf
Transaction_Num = 304
Transaction_NumInt = Val(Transaction_Num)
Transaction_Num = str(Transaction_NumInt)
customer = "5"
Location = "2"
Weight = "3"
Sort_Class = "4"
'- See above: Entered the URL http://ics.etechsystems.com:3000/colmac/new_load
strPostData = strPostData & "<new_load>" & vbCrLf
strPostData = strPostData & "<transaction_number>" & Transaction_Num & "</transaction_number>" & vbCrLf
strPostData = strPostData & "<customer>" & customer & "</customer>" & vbCrLf
strPostData = strPostData & "<location>" & Location & "</location>" & vbCrLf
strPostData = strPostData & "<weight>" & Weight & "</weight>" & vbCrLf
strPostData = strPostData & "<sort_class>" & Sort_Class & "</sort_class>" & vbCrLf
strPostData = strPostData & "</new_load>" & vbCrLf
strHeaders = "Content-Type:text/xml" & vbCrLf & _
"Content-Length:" & Len(strPostData) & vbCrLf
strHTTP = strHTTP & strHeaders
strHTTP = strHTTP & vbCrLf
strHTTP = strHTTP & strPostData
txtRequest.Text = strHTTP
winsock.Connect
' wait for a connection
While Not blnConnected
DoEvents
Wend
' send the HTTP request
winsock.SendData strHTTP
thestring = "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://ics.etechsystems.com:3000/colmac/get_load/" + Transaction_Num
Shell thestring
txtResponse = "Transaction Number: " + Transaction_Num
Transaction_Num = str(Transaction_NumInt + 1)
End Sub
Sub winsock_Connect()
blnConnected = True
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|