如何采用HTTP POST方式,给对方SP发送一个sequence_id=1234&service_num=22332211的数据呢
解决方案 »
- WF4如何加载工作流实例
- sqlite+c# 带数据库函数时查询不出数据,急求答案中……
- datagrid 如何在鼠标滑动时调用后台方法
- 为何不能重载父类中的方法
- 我定义了一个类库,在一个.cs文件中使用HttpContext.Current.Server.MapPath,编译提示"找不到类型或命名空间名称“HttpContext",而我已
- 想学C#,各位达人能不能推荐几本入门书籍?
- socket编程
- [求助]急,有StreamWriter和File class 问题
- C# winform调用java发布的webservice时,如何获得webservice中某一方法对应的response
- 如何将二进制的值写如注册表?
- 如何在登陆页面里,有选择的进入其他winfrom
- 如何利用自己架设的邮件服务器发信
<<.Net网络高级编程>> 这本书里面有讲.
response = webClient.DownloadData(LOGIN_URL);string viewstate = ExtractViewState(
Encoding.ASCII.GetString(response)
);string postData = String.Format(
"__VIEWSTATE={0}&UsernameTextBox={1}&PasswordTextBox={2}&LoginButton=Login",
viewstate, USERNAME, PASSWORD);webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
response = webClient.UploadData(
LOGIN_URL, "POST", Encoding.ASCII.GetBytes(postData)
);
url here:
http://odetocode.com/Articles/162.aspx
private void Button5_Click(object sender, System.EventArgs e)
{
// first, request the login form to get the viewstate value
HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
StreamReader responseReader = new StreamReader(
webRequest.GetResponse().GetResponseStream()
);
string responseData = responseReader.ReadToEnd();
responseReader.Close();
// extract the viewstate value and build out POST data
string viewState = ExtractViewState(responseData);
string postData =
String.Format(
"__VIEWSTATE={0}&UsernameTextBox={1}&PasswordTextBox={2}&LoginButton=Login",
viewState, USERNAME, PASSWORD
);
// have a cookie container ready to receive the forms auth cookie
CookieContainer cookies = new CookieContainer(); // now post to the login form
webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = cookies;
// write the form values into the request message
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postData);
requestWriter.Close();
// we don't need the contents of the response, just the cookie it issues
webRequest.GetResponse().Close();
// now we can send out cookie along with a request for the protected page
webRequest = WebRequest.Create(SECRET_PAGE_URL) as HttpWebRequest;
webRequest.CookieContainer = cookies;
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
// and read the response
responseData = responseReader.ReadToEnd();
responseReader.Close();
Response.Write(responseData);
}