会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Gary yang's Bolog
HttpWebRequest[post/get]
Post
Code
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
strId
=
"
Button
"
;
string
strPassword
=
"
123456
"
;
ASCIIEncoding encoding
=
new
ASCIIEncoding();
string
postData
=
"
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTE5MjM1NTUxODdkZN5XxVrQd%2FknWoWN37VZr71vQgKn&__PREVIOUSPAGE=wVE_UGSoWjG65-rQk8wSB2QnduBi7s5pGYGv9nl2ZQU1&__EVENTVALIDATION=%2FwEWBAL8nqGpAwLs0bLrBgK7q7GGCAKM54rGBtY9qZGqnqJlQWAFDV3VO%2B0ab8qq&Button2=
"
+
strId;
postData
+=
(
"
&TextBox1=
"
+
strPassword);
byte
[] data
=
encoding.GetBytes(postData);
//
Prepare web request
HttpWebRequest myRequest
=
HttpWebRequest.Create(
"
http://localhost:1222/NormalProjectSite/TargetPost.aspx
"
)
as
HttpWebRequest;
myRequest.Method
=
"
POST
"
;
myRequest.ContentType
=
"
application/x-www-form-urlencoded
"
;
myRequest.ContentLength
=
data.Length;
Stream newStream
=
myRequest.GetRequestStream();
//
Send the data.
newStream.Write(data,
0
, data.Length);
newStream.Close();
//
Get response
HttpWebResponse myResponse
=
(HttpWebResponse)myRequest.GetResponse();
StreamReader reader
=
new
StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string
content
=
reader.ReadToEnd();
posted on
2009-08-22 10:37
博览潇湘
阅读(
266
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理