Click to See Complete Forum and Search --> : Posting data to a CGI script
windysky
May 2nd, 2006, 08:21 PM
Dear all,
I would like to know how to post data to a CGI script from a windows application. I've searched for answers days but couldn't find a right answer.
If you go to the following webpage, it allows chemical structure searches. http://pubchem.ncbi.nlm.nih.gov/search/
For example, if you enter C1=CC=CC=C1 to the 'Search SMILES and Formula' text box and click the 'Search' button,
it will send data to
http://pubchem.ncbi.nlm.nih.gov/search/PreQSrv.cgi
I would like to implement this function directly onto my program.
Would anyone please let me know
1. how to post data to a CGI script?
2. get the result back?
Your kind help would greatly help me.
Thank you so much in advance,
Best,
Mike
WizBang
May 3rd, 2006, 05:15 AM
You can do what you want with the CSocket class or the winsock control.
Here's my post on how to use Winsock or the CSocket class to POST data to a web page:
http://www.codeguru.com/forum/showthread.php?t=237013#post701796
Let us know how it goes.
windysky
May 3rd, 2006, 08:54 AM
Thanks WizBang,
I found out that I post my thread to a wrong forum. It should be in Visual Basic .Net not 6.0. I am sorry about that.
Would you let me know how to do same thing in VB .NET if are aware of?
Thank you and I will put this post .NET forum as well.
Best,
Mike
WizBang
May 3rd, 2006, 09:45 AM
[ Moved Thread ]
WizBang
May 3rd, 2006, 09:50 AM
The data you send in the POST to the server will be the same no matter what language you are using, and I'm sure there are numerous threads showing how to use winsock or equivelent for it. If not, then Google will surely turn up something. Now that you have the format for the POST, the rest will be fairly simple I'm sure.
DSJ
May 4th, 2006, 04:59 PM
Take a look at the WebClient class.
Craig Gemmill
May 4th, 2006, 06:07 PM
I've stripped down and modified a function from one of my apps that performs a POST in a separate Request/Response. It should be exactly what you need, or close enough to get you going:
Dim _Url As String = "http://www.crgitsolutions.com"
Dim _FormPostData As String
Dim _FormPostBytes As Byte()
Dim _Encoding As New ASCIIEncoding
Dim _Request As Net.HttpWebRequest = CType(Net.WebRequest.Create(_Url), Net.HttpWebRequest)
Dim _Stream As IO.Stream
Dim _Response As Net.HttpWebResponse
Dim _StreamReader As IO.StreamReader
Try
_FormPostData = "myValue=1&myOtherValue=2"
_FormPostBytes = _Encoding.GetBytes(_FormPostData)
_Request.KeepAlive = True
_Request.Method = "POST"
_Request.ContentType = "application/x-www-form-urlencoded"
_Request.ContentLength = _FormPostBytes.Length
_Stream = _Request.GetRequestStream
_Stream.Write(_FormPostBytes, 0, _FormPostBytes.Length)
_Stream.Close()
_Response = CType(_Request.GetResponse, Net.HttpWebResponse)
_StreamReader = New IO.StreamReader(_Response.GetResponseStream)
Do While Not _StreamReader.EndOfStream
'
'You can read in the HTTP response here
'
Loop
_StreamReader.Close()
_Response.Close()
Catch ex As Exception
Response.Write(ex.Message)
End Try
windysky
May 4th, 2006, 08:10 PM
Thank you WizBang, DSJ, and Craig Gemmill,
I will take a close look at them.
Thank you all again for your kind help.
Best,
Mike
VBhobbiest
September 21st, 2006, 04:24 AM
I was searching for something VERY similer, and stumbled upon this post. Although a little old, its a great post for POST (small lame joke) I have 1 question regarding this line:
_FormPostData = "myValue=1&myOtherValue=2"
I've concluded that this is the method used for submitting the values of user controls. However what attribute does it represent in HTML? the name? tag? ID? Class? - I mean the "myValue" part obviously "1" represents the value of the control =)
I appologize for sounding ignorant - apperently I didn't get the memo (another BAD joke) - If anyone could clear this up for me, I'd appreciate it.
Thanks,
Dave
sotoasty
September 21st, 2006, 07:31 AM
It represents the "NAME" portion of the control. That is what gets passed to the next page. In this case, I would think there is would be some html that looks like....
<INPUT NAME="myValue" TYPE="TEXT">
<INPUT NAME="myOtherValue" TYPE="TEXT">
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.