POST表单数据从后面的代码到远程URL

时间:2013-09-24 05:28:42

标签: asp.net httpwebrequest

您好我正在开发一个应用程序,我希望在单击按钮时将表单数据从代码后面发送到远程URL.IT应该从按钮的onclick事件执行代码并使用重定向将该数据发布到远程URL。即发布后它应该重定向到新的URL。

我尝试使用Web请求发布数据,如下所示,但它在同一页面上给出响应,因为它不会重定向到远程URL。

       string url = "remote URL";

        StringBuilder postData = new StringBuilder();

        postData.Append(Encrypted);           

        //ETC for all Form Elements

        // Now to Send Data.
        StreamWriter writer = null;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = postData.ToString().Length;
        try
        {
            writer = new StreamWriter(request.GetRequestStream());
            writer.Write(postData.ToString());
        }
        finally
        {
            if (writer != null)
                writer.Close();
        }

        Response.Redirect("URL"); 

0 个答案:

没有答案