Google グループは Usenet の新規の投稿と購読のサポートを終了しました。過去のコンテンツは引き続き閲覧できます。
Dismiss

Using the POST method with HttpWebRequest

閲覧: 47 回
最初の未読メッセージにスキップ

Tony

未読、
2003/12/09 10:49:232003/12/09
To:
Hi all,

I can use the HttpWebRequest object to scrape a page with
a GET. However, if I need to post some data do a page,
how do I do that? I can set the method property
to "POST", but then how do I tell it what data to send
(ie "zip=12345&month=5")?

Thanks

Martin Honnen

未読、
2003/12/09 11:28:302003/12/09
To:

Tony wrote:

Use GetRequestStream() and write the data to the stream and close the
stream after you have set the method to POST.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Eric Veltman

未読、
2003/12/09 12:14:412003/12/09
To:
Tony wrote:

Hello Tony,

I've never done this myself, but I think you need
to use the GetRequestStream() method and then use
the returned stream to send the data to the server.

Best regards,

Eric

vMike

未読、
2003/12/09 15:24:162003/12/09
To:
Here is a real simple cookieless example this is a snip where stringPost is
the string of data you want to post and stringResponse is a string which
will hold the response.

Dim mgWebRequest As HttpWebRequest
Dim mgWebResponse As HttpWebResponse
Dim mgStreamWriter As StreamWriter
Dim mgStreamReader As StreamReader
mgWebRequest =CType(WebRequest.Create(http://post.site.com) ,
HttpWebRequest)
mgWebRequest.Method = "POST"
mgWebRequest.ContentLength = stringPost.Length
mgWebRequest.ContentType = "application/x-www-form-urlencoded"
mgStreamWriter = Nothing
mgStreamWriter = New StreamWriter(mgWebRequest.GetRequestStream())
mgStreamWriter.Write(stringPost)
mgStreamWriter.Close()
mgWebResponse = CType(mgWebRequest.GetResponse(),HttpWebResponse)
mgStreamReader = New StreamReader(mgWebResponse.GetResponseStream())
stringResult = mgStreamReader.ReadToEnd()
mgStreamReader.Close()


It gets much more complicated if you need to pass or receive cookies or
files.

"Tony" <tony_n-o...@ch1ps.com> wrote in message
news:102fb01c3be6c$0482eb20$a601...@phx.gbl...

Tony

未読、
2003/12/09 20:29:422003/12/09
To:
That helps a lot, thanks everyone!
新着メール 0 件