1

您好我正在开发一个应用程序,我想在单击按钮时将表单数据从后面的代码发布到远程 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"); 
4

0 回答 0