//提交方法
private void GetIMG(string url, string html)
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
//需要一个String暂存HTML的值
string postdata = html;
//头部(动态)
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
byte[] arrB = encode.GetBytes(postdata);
myRequest.Method = "POST";
myRequest.ContentType = "text/html";//x-www-form-urlencoded//ContentType需要对应页面相应类型
myRequest.ContentLength = arrB.Length;
Stream outStream = myRequest.GetRequestStream();
outStream.Write(arrB, 0, arrB.Length);
outStream.Close();
HttpWebResponse HttpWResp;
try
{
HttpWResp = (HttpWebResponse)myRequest.GetResponse();
}
catch (WebException ex)
{
HttpWResp = (HttpWebResponse)ex.Response;
}
}
//接收页面
protected string postStr;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.HttpMethod.ToLower() == "post")
{
Stream stream = System.Web.HttpContext.Current.Request.InputStream;
byte[] b = new byte[stream.Length];
stream.Read(b, 0, (int)stream.Length);
postStr = Encoding.UTF8.GetString(b);
HtmlToImg.Html = postStr;
}
if (HtmlToImg.Html != null) //htmlToImage.Html 为静态方法
{
postStr = HtmlToImg.Html;
}
}
//绑定数据源
<div style="margin-left: -18px; margin-top: -16px;">
<%=postStr%>
</div>
Post提交数据
最新推荐文章于 2022-10-22 15:56:52 发布