Results 1 to 11 of 11

Thread: Inet1.Execute strURL, "POST", strDATA

  1. #1
    Guest

    Post

    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?

  2. #2
    Guest

    Post

    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 - [email protected])" & 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 = "[email protected]"

    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
    [email protected]

  3. #3
    Guest

    Post

    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.

  4. #4
    Guest

    Post

    ""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
    [email protected]

  5. #5
    Guest

    Post

    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.

  6. #6
    New Member
    Join Date
    May 1999
    Posts
    1

    Post

    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.

  7. #7
    Addicted Member
    Join Date
    Jan 1999
    Posts
    173

    Post

    I am getting icRequestFailed error "Unable to complete request" on the Inet1.Execute sUrl, "POST", sFormData, vbCrlf & vbCrlf & sHeaders

  8. #8
    Member
    Join Date
    Jun 2000
    Location
    Hong Kong
    Posts
    62
    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:

    Code:
        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!
    Please Visit My WebCam!!
    http://www.hmcheung.com

  9. #9
    Addicted Member
    Join Date
    Mar 2006
    Posts
    186

    Re: Inet1.Execute strURL, "POST", strDATA

    VB Code:
    1. ImBusy:
    2.             DoEvents
    3.             'we want to let it finish do whatever it does:
    4.             If Inet1.StillExecuting = True Then GoTo ImBusy:
    or this:
    VB Code:
    1. If Inet1.StillExecuting = True Then Inet1.Cancel

  10. #10
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Inet1.Execute strURL, "POST", strDATA

    lol, this thread is 6 years old ...

  11. #11
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Re: Inet1.Execute strURL, "POST", strDATA

    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.
    Last edited by DavidNB; Nov 26th, 2008 at 10:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width