Post提交数据

来源:互联网 发布:mysql导出表数据 编辑:程序博客网 时间:2024/06/05 18:25
 //提交方法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>

0 0