关闭

Post提交数据

132人阅读 评论(0) 收藏 举报
 //提交方法
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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:51177次
    • 积分:1077
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:37篇
    • 译文:0篇
    • 评论:3条