How to use HttpWebRequest to send POST request to another web server?
来源:互联网 发布:淘宝商标注册靠谱吗 编辑:程序博客网 时间:2024/05/16 08:37
How to use HttpWebRequest to send POST request to another web server?
要提交象以下格式的表单:
<form name="_xclick" target="paypal"
action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="me@mybiz.com">
<input type="hidden" name="item_name" value="HTML book">
<input type="hidden" name="amount" value="24.99">
<input type="image" src="http://www.paypal.com/images/sc-but-01.gif"
border="0" name="submit" alt="Make payments with PayPal!">
<input type="hidden" name="add" value="1">
</form>
POST方法写法如下:
private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();
//读取response
res = (HttpWebResponse)req.GetResponse();
Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding(utf-8);
StreamReader sr = new StreamReader( ReceiveStream, encode );
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
while (count > 0)
{
String str = new String(read, 0, count);
strResult = str;
count = sr.Read(read, 0, 256);
}
}
- How to use HttpWebRequest to send POST request to another web server?
- How to use HttpWebRequest to send POST request to another web server?
- How to use HttpWebRequest to post data to another page which is on another server
- How to use HttpURLConnection POST data to web server?
- How to use HttpURLConnection POST data to web server?
- How to send HTTP request GET/POST in Java
- How to use the HttpWebRequest object
- How to use HttpWebRequest and RegularExpressions to crash website
- How to send HTTP request in java?
- How to send pull request on Git
- how to use UrlConnection to post/get request with basic authorization?
- how to send email
- How to use another indicator in your code?
- How to bounce Web server
- use c to send file using http post
- how to use command via proxy server
- How to enable Android dhcpcd send hostname request
- Use Http Post to call Web Service
- ASP.NET中的Http Handler
- 测试一下拉
- [转]水木不在,何以清华?
- Splash窗体的完美实现
- 感觉不错~~~
- How to use HttpWebRequest to send POST request to another web server?
- 刷街前必须要会的技巧
- 2005年的第一个意外之喜
- 开发记录-05.3.26_2
- 忧郁中的杂记
- 因为他们想要找回他们的国家!
- 轮滑刹车技巧
- What is SOA?----------对SOA的思考,以及由此想到的人类社会的发展 (转)
- 单排轮滑的旋转技巧