PDA

Click to See Complete Forum and Search --> : Inet1.Execute strURL, "POST", strDATA


Mar 29th, 1999, 12:10 AM
My "POST"'s with the Inet.Execute method do not give consistent results. Also, when I implement an Inet.GetChunk method, I get incomplete data as Shan reports in his question. My posts are sending and receiving data to a perl script. Any ideas?

Apr 5th, 1999, 11:48 AM
Not sure what you mean by inconsistent results but here is a couple of "UnTested" Subs that may allow an application to subscribe to VB-World's Free NewsLetter

(My first post so I don't know how this is going to look!)

Add a new VB Form
Put an Inet Control on it and name it Inet_Subscribe
Add a Submit button. In the Click Event call SubscribeFreeNewsLetter()
Add a text box, make it multiline - vertical scrolling
Add a label and name it lblSatus

'VB-World Subscription Form Values -

'form METHOD="POST" ACTION="http://www.vb-world.net/cgi-bin/subscribe.cgi"
'input type="hidden" name="method" value="subscribe"
'input TYPE="text" NAME="email" SIZE="10" value="your email"

Private Sub SubscribeFreeNewsLetter()

Dim sURL As String
Dim sSubscribeNameValue As String
Dim sEmailName As String
Dim sEmailValue As String
Dim sFormData As String
Dim sHeaders As String

'This is a spoof... sortof..
sHeaders = "Accept-Language: en-us" & vbCrLf & "Referer: http://www.someplace.com" & vbCrLf & "Content-Type: application/x-www-form-urlencoded" & vbCrLf & "User-Agent: YourProgramName (compatible; MSIE 4.01; Windows 95 Problems? email - DeveloperEmail@develop.com)" & vbCrLf & "Accept: */*" & vbCrLf & "accept-encoding: gzip/dflate" & vbCrLf & "Host: YourHost.com" & vbCrLf & vbCrLf

sURL = "http://www.vb-world.net/cgi-bin/subscribe.cgi"
sSubscribeNameValue = "&method=subscribe"
sEmailName = "&email="
sEmailValue = "MyEmail@email.com"

sFormData = sSubscribeNameValue & sEmailName & sEmailValue

Inet_Subscribe.Execute sURL, "POST", sFormData, vbCrLf & vbCrLf & sHeaders


Do Until Inet_Subscribe.StillExecuting = False
DoEvents
Loop

Screen.MousePointer = vbArrow

End Sub

Private Sub Inet_Subscribe_StateChanged(ByVal State As Integer)

Dim vtData As Variant
Dim sData As String: sData = ""
Dim bDone As Boolean: bDone = False

Screen.MousePointer = vbHourglass

'Which state has the control entered?
Select Case State
Case icResolvingHost ' 1
lblStatus.Caption = " Looking up IP address of host computer"
Case icHostResolved ' 2
lblStatus.Caption = "IP address found"
Case icConnecting ' 3
lblStatus.Caption = "Attempting to connect to Host"
Case icConnected ' 4
lblStatus.Caption = "Connected"
Case icRequesting ' 5
lblStatus.Caption = "Making Request"
Case icRequestSent ' 6
lblStatus.Caption = "Request sent"
Case icReceivingResponse ' 7
lblStatus.Caption = "Chatting with Host..."
Case icResponseReceived ' 8
lblStatus.Caption = "Response received"
Case icDisconnecting ' 9
lblStatus.Caption = "Disconnecting"
Case icDisconnected ' 10
lblStatus.Caption = "Disconnected"
Case icError ' 11
lblStatus.Caption = "Error " & Inet_Subscribe.ResponseCode & " " & Inet_Subscribe.ResponseInfo

Screen.MousePointer = vbArrow
'CODE TO HANDLE ERROR
Exit Sub
Case icResponseCompleted ' 12


'Has the complete response been received?
'Get the first chunk of the HTML document 'fromthe Net Control

vtData = Inet_Subscribe.GetChunk(1024, icString)

'Is there nothing in the document?

If Len(vtData) = 0 Then
'if so, then we are done here
'maybe assign a message to sData
bDone = True
End If

'Loop until we have extracted the entire 'document from the Inet_Subscribe Control

Do While Not bDone
'Add the newly extracted chunk to the 'previously extracted portion of the document

sData = sData & vtData

'Extract the next portion of the document 'from the Inet_Subscribe Control

vtData = Inet_Subscribe.GetChunk(1024, icString)

'Have we reached the end of the document?

If Len(vtData) = 0 Then
'If so, set the flag to indicate that we
'are done

bDone = True
End If

Loop

'Parse the server's response...
'Send sData to get parsed...
'Call ParseData(sData)

'Or simply show the results in a text box
Text1.Text = sData

End Select

End Sub



------------------
Dave
deccles@pacbell.net

Apr 5th, 1999, 06:52 PM
Thanks for the reply. "Inconsistent" means-If I try it more than once, I get different results.

1) Do you know if the CGI script at "http://www.vb-world.net/cgi-bin/subscribe.cgi" is running on UNIX?
Making sure I add or strip "vbCrLf"'s is important here.
2) Can you explain how important the "vbCrLf & vbCrLf & sHeaders" parameters are in the Inet_Subscribe.Execute method?
3) What limitations are there in size? {i.e. the 1024 in "vtData = Inet_Subscribe.GetChunk(1024, icString)}" Making this number smaller also helped a little.

Thanks.

Apr 5th, 1999, 09:40 PM
""Inconsistent" means-If I try it more than once, I get different results."

My experience is either it works or it doesn't. Check the scope of your variables or look for some kind of logic error in your code that may be changing a value. Maybe a buffer problem... see below.

Re: Unix. I don't really know how to tell for sure other than the .html suggests it could be but if the pages were .htm it certainly wouldn't be.

RE: "important the "vbCrLf & vbCrLf & sHeaders" parameters"

Headers are how your program and the server communicate with each other. HTML is how your program and the server communicate with a user (in the case of a browser)

This may be part of your "inconsistent" problem. The server may be sending your program a response header with HTTP Status Codes telling you something is wrong and you aren't getting it. Ie., 400 - Bad Request or 401 - Unauthorized or 403 - Forbidden... (there's more)

If you use the headers, it's very important. I am not sure a POST would work without the above minimum headers but I have never tried to submit without.

According to RFC's you should send headers. I believe you are also supposed to send the actual content length but I don't.

I use the header to identify my program and give my email address if something were to go wrong. If you were to use the code to subscribe and you inadvertantly put the VB-World's server into a loop running your code, An administrator would want to know who or what the offending program is and let you know you are messing up.

BTW, If you are building a BOT then you might do some searches on this as there are some BOT specific rules you should follow.

Re: "the 1024" and "Making this number smaller also helped a little."

I believe this is a default value that has something to do with a buffer. I don't know but maybe if you are having a problem with a 1024 byte chunk this may be the cause of your inconsistant problem.


------------------
Dave
deccles@pacbell.net

Apr 7th, 1999, 03:12 AM
Thanks. I think it's the "requestHeaders" portion. My documentation says "Optional", but maybe it expects other properties to be set if omitted in the Execute method.
Also, I am talking to UNIX, so I have to check the CR's and LF's. That made all the difference when I used the Winsock control.

cirrgang
May 24th, 1999, 04:56 PM
I tried the code listed above and was also having problems with not getting all the requested data returned. There was never any consistency to how much data would be returned by the GetChunk calls. I added "DoEvents" calls after both GetChunk calls and have been successful since.

vbsquare
Jul 24th, 1999, 02:05 AM
I am getting icRequestFailed error "Unable to complete request" on the Inet1.Execute sUrl, "POST", sFormData, vbCrlf & vbCrlf & sHeaders

hmcheung
Jun 18th, 2000, 04:51 PM
Hi,

I've tried the above code. it works for retrieving a single CGI URL , but if I put it in a loop like this:


While (Not rsMain.EOF) And (InetFlag = True)
Inet1.Execute Trim(rsMain("link")), "GET"
rsMain.MoveNext
Wend


but I get an error 35764 "still executing last request". How can I solve this problem? Thanks! :)

foxter
Jul 5th, 2006, 04:50 PM
ImBusy:
DoEvents
'we want to let it finish do whatever it does:
If Inet1.StillExecuting = True Then GoTo ImBusy:

or this:

If Inet1.StillExecuting = True Then Inet1.Cancel

rory
Jul 5th, 2006, 06:27 PM
lol, this thread is 6 years old ... :D

DavidNB
Nov 25th, 2008, 09:28 AM
First of all I must say I am sorry.

I know this thread is 8 years old, but I need help with this particular command.

I need to send a request "POST" to an aspx page (not my server) to request information based on the zip code. (I have a file containing all zip codes and must query all the codes directly in my program without browser)

Once the request is sent I need to retreive another aspx page using a GET to have the right data to further analyze.

My current problem is that I know what the url is and the formdata, but there is a problem with how I give the header.

So to clear some (I hope)

I have : www .url. com/searchpage.aspx (which contains a text box for zip code and a submit button)

Once I sent the request here it should return :

www .url .com/resultpage.aspx (with information based on the zip code I entered)


I don't have extended knowledge of ASP .NET so it is difficult.

My program is in VB6.0 and I use inet. Since my header is not correct, I don't have the right results from the execute command. The command take my header variable and add it inside the misc section of a header it built itself.

It has been a while since I last used this type of forum so I hope I made my situation clear enough to get some help and that there are still someone out there that may have the solution.

Thanks

EDIT!!

I found my problems. I had to rebuild the header in the code from the txt file I had to make sure the Carriage return were there and then in my last part I had to use the & instead of just & so it entered all the extra parameters.