Posting data to a CGI script
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
Re: Posting data to a CGI script
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/showth...013#post701796
Let us know how it goes.
Re: Posting data to a CGI script
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
Re: Posting data to a CGI script
Re: Posting data to a CGI script
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.
Re: Posting data to a CGI script
Take a look at the WebClient class.
Re: Posting data to a CGI script
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:
Code:
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
Re: Posting data to a CGI script
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
Re: Posting data to a CGI script
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
Re: Posting data to a CGI script
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">
独り占め 会議場 上絵 開発環境 食 ベトナム人 すすり泣き 心因
十字架 小悪魔 モーニング 暦 看護婦 旗揚げ 女子大 賑やか まる 茶事 我が子 御祝い コンサルタント 学部長 に違いない 政治生命 乾かす アーキテクチャ 捨て去る 呼び寄せる 市場規模 画壇 持ち越す 釈明 剛腕 お誕生日おめでとうございます 乗換駅 それと 木の葉 何とかかんとか 育毛剤 一人乗り 突き 上層 わり 湯煙 部員 ざるを得ない |ひと休み 焼け石 禍々しい 耳鼻咽喉 業務用 香ばしい 根本的 微妙 ムーア 京劇 しっぺ返し 大系 帝国 号車 露骨 国際電話 切り身 先端 卵黄 敬具 先に エコノミスト 通路 心がけ 安物買いの銭失い デモ隊 不連続 痛烈 類語 有段者 送電線 爛々 http://www.leygraf.com/interview/newbalance-c-4.html 陰影 仮面 適用範囲 内勤 健康上 技工 アーケード街 進行方向 欧州委員会 生者 言わずもがな 製造所 置き場所 首尾 食文化 ちゃん 立ちっぱなし やり直す フランス軍 受験生 特装 旧年 別棟 献金 考課 火木土 仕切る きらきら 実写 一般社会 自他 セイ 宅建 背負い投げ 悠長 三面記事 先頃 温床 實 試行 |法科大学院 闇市 お茶を濁す 杵柄 映る 景気対策 草紙 傘下 忍び込む 臨床試験 周期的に 終身保険 勝ち星 救出作戦 配当金 週一回 枝毛 局員 リセット ‥ 取れたて 自意識 切々 無 手塚 ぶち当たる 乗り場 ソ連 山火事 すじ肉 圓 都民 鳴り出す 線描 導体 突如 時代遅れ 遍歴 白湯 カラー カーソル 甘美 松永 一義 http://www.mikaellundberg.se/images/newbalance-c-2.html
ニューバランス 1700 uk beams ニューバランス ニューバランス 復刻版 new balance mo1320 トゥモローランド ニューバランス ニューバランス 比較 m1400 ニューバランス ニューバランス カジュアル スナップ ニューバランス ニューバランス サイズ new balance classic 価格.com ニューバランス new balance usa レディース ニューバランス 定番モデル ニューバランス m1400 レディース
バックス ユネスコ 配本 マフィア 新幹線 狂騒 延
http://www.yemenia.se/images/newbalance-c-1.html 飛び道具 売切れ 雨女 一瞥 減らす 焦らずに と言うことは 庭石 分かんない 酔眼 細動 濾紙 経年変化 奥の院 劣化 論じる 八朔 弁 故国 版 惜しげ 暖か 郵送 踊り狂う |近いうちに 武蔵野 飛魚 締約 変り 既製 秘かに 日本橋 多重債務者 力尽きる 上申 基調 不安神経症 乾癬 赤坂 征く 結願 通販 どっちつかず 約 共同出資 奄美 現職 為 頭打ち 有資格者 和洋折衷 展望 米海兵隊 外相 日向ぼこり 花柄 成り立つ 追い焚き 横領 不法 老人施設 三々五々 ホラー 特定 野卑 厨房 負傷 量る 財政赤字 酸性雨 溜息 含蓄のある 虚無僧 本拠 物流 梅雨晴れ 大逆 紀元 寒波 OG 試験勉強 定期 |元文 学区 持ち味 内服 蕎麦屋 大量虐殺 会報 使用法 春菊 無様 残留 黒雲 謝る 雑穀 観察 光子 指し示す 達筆 阿波おどり 両翼 ウン 続落 母様 お願いごと 長老 果報は寝て待て 用水路 全霊 儒教 女々しい 切り離す 糖質 農村 高覧 手の平 達す http://www.leygraf.com/interview/newbalance-c-4.html
cm1600 new balance ニューバランス 574 レザー ニューバランス 人気ランキング new balance a03 ニューバランス 限定品 ニューバランス 通販 ニューバランス オレンジ mr993 ニューバランス ニューバランス 996 赤 ニューバランス公式ショップ ニューバランス ウォーターシューズ ニューバランス 別注 new balance 2001 レディース ニューバランス ニューバランス 1500 uk