Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Please help a newbie

Posted on 2000-05-07
4
Medium Priority
?
149 Views
Last Modified: 2010-05-02
Hi guys, Newbie here,

I am using Visual Basic 6.0(SP3) and am using the inet.execute "POST" function to send some name=value pair variables to a VB CGI script. I didn't write the CGI script but this is what it looks like to get the input

****************************************************

Public Function CGIStdIn() As String

Dim lngStdInput As Long                 ' Handle of Standard Input
Dim strStdInput As String               ' String of Standard Input
Dim lngNumberOfBytesToRead As Long      ' Number of bytes in standard input
Dim lngNumberOfBytesRead As Long        ' Number of bytes read in standard input
Dim typOverlapped As OVERLAPPED         ' Structure used in ReadFile() function call
Dim lngResult As Long                   ' Did Standard Input Work?

    On Error Resume Next
   
    lngStdInput = GetStdHandle(STD_INPUT_HANDLE)    ' Get standard input handle
    CGIStdIn = ""
   
    If lngStdInput > -1 Then                        ' If a valid handle was found

' Find out how big the input stream is

        lngNumberOfBytesToRead = CLng(Environ("CONTENT_LENGTH"))
       
' Initialize string variable to store the standard input stream

        strStdInput = String(lngNumberOfBytesToRead, " ")
        lngResult = ReadFile(lngStdInput, strStdInput, lngNumberOfBytesToRead, _
                        lngNumberOfBytesRead, typOverlapped)
        strStdInput = RTrim(strStdInput)            ' Get rid of any trailing spaces
        CGIStdIn = strStdInput       ' Return standard input stream
    End If

    If CGIStdIn <> "" Then
   
' Add the tail of the string if <CR> was hit instead of the login button
       
        If Right(CGIStdIn, 1) <> "&" Then
            CGIStdIn = CGIStdIn & "&Login_Submit=Login"
        End If
    End If

End Function

*****************************************

Now here's the problem, it works fine when you push the login button from the browser, but when I try to use my VB application to post info to the script, all I get is a No response timeout. Can anyone help me with a reason why the VB CGI script does not like this POST?

I'm pretty sure my code should work, all indications from examples suggest it should.

Private Sub cmdPOST_Click()
   picTic.Visible = True
   txtData.Text = ""
   
   Dim fnum As Integer
   Dim file_name As String
   Dim got_file As Boolean
   Dim txt As String

    ' Get the file's name.
    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
    file_name = file_name & "logins.txt"
   
    ' Open the file.
    fnum = FreeFile
    On Error Resume Next
    Open file_name For Input As fnum
    got_file = (Err.Number = 0)
    On Error GoTo 0

    If got_file Then
        ' Read the text.
        Do Until EOF(fnum)
        Dim i As Integer
        Dim sArray As Variant
            Input #fnum, txt
            sArray = Split(txt)
            txtRemotePath.Text = "MNO=" & sArray(0) & "&PWD=" & sArray(1) _
            & "&BSB=NTV25"
        Loop
        ' Close the file.
    Close fnum
    End If
   
   Inet1.Execute txtURL.Text, "POST", txtRemotePath.Text, _
   "enctype: application/x-www-form-urlencoded"
   
    Exit Sub

End Sub

Thanks in advance
nathan
0
Comment
Question by:GnatMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 300 total points
ID: 2787032
The method you are using looks OK.  Perhaps there is something wrong with the parameters.  Try hardcoding the URL and post data to see if this is the case.  I tried a POST to Altavista, and it seems to work fine:

Option Explicit

Private Sub Command1_Click()
    Dim sURL As String, sPost As String, sHeader As String
    sURL = "http://www.altavista.com/cgi-bin/query"
    sPost = "pg=q&sc=on&hl=on&q=%2Bvb&kl=XX&stype=stext"
    sHeader = "Content-Type: application/x-www-form-urlencoded"
     
    Inet1.Execute sURL, "POST", sPost, sHeader
   
    Command1.Enabled = False
End Sub

Private Sub Form_Load()
    'RichTextBox (rtb) for reading response
    rtb.RightMargin = Screen.Width * 2
    rtb.Left = 0
    ''Set at design time
    ''rtb.ScrollBars = rtfBoth
End Sub

Private Sub Form_Resize()
    rtb.Width = ScaleWidth
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
    Case icResponseCompleted ' 12
        Dim vtData As Variant ' Data variable.
        Dim strData As String: strData = ""
        Dim bDone As Boolean: bDone = False
   
        ' Get first chunk.
        vtData = Inet1.GetChunk(1024, icString)
        DoEvents
        Do While Not bDone
            strData = strData & vtData
            DoEvents
            ' Get next chunk.
            vtData = Inet1.GetChunk(1024, icString)
            If Len(vtData) = 0 Then
                bDone = True
            End If
        Loop
        rtb.Text = strData
        Command1.Enabled = True
   End Select
End Sub
0
 

Author Comment

by:GnatMan
ID: 2787053
Thanks for the suggestion, I hardcoded in the parameters for the POST and it didn't seem to do much good though. Any further help from anyone would be just swell..
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2787215
Does the site work if you type in the POST directly into the address bar of your Browser?

e.g.

http://www.foo.com/foo?a=b&c=d
0
 

Author Comment

by:GnatMan
ID: 2787338
I've tried that, it doesn't work either, that's using the GET method though isn't it? Isn't the CGI VB script grabbing the info from STDinput from POSTed data?

Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question