csharp HttpWebRequest的提交后数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp HttpWebRequest的提交后数据相关的知识,希望对你有一定的参考价值。
private string PostWebRequest(string postUrl, string paramData, Encoding dataEncode) { string ret = string.Empty; try { byte[] byteArray = dataEncode.GetBytes(paramData); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; Stream stream = request.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default); ret = sr.ReadToEnd(); sr.Close(); response.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return ret; }
以上是关于csharp HttpWebRequest的提交后数据的主要内容,如果未能解决你的问题,请参考以下文章
csharp 模拟HttpWebRequest - CustomWebRequest
csharp 模拟HttpWebRequest - SUT
HttpWebRequest 表单提交
利用HttpWebRequest模拟表单提交
c# httpwebrequest 模拟登陆
C# 模拟 post提交php页面的表单