C# 将用户重定向到Paypal站点,并以编程方式从codebehind获取数据

C# 将用户重定向到Paypal站点,并以编程方式从codebehind获取数据,c#,asp.net,forms,paypal,C#,Asp.net,Forms,Paypal,我的情况是这样的,我必须重定向用户到贝宝网站的数据作为结果,当贝宝支付页面将显示,然后用户信息将自动填写。我试过了,但失败了。在本地,我试图模拟代码的问题 test.aspx 上面的代码将用户重定向到test1.aspx页面以及数据 我试图从test1.aspx页面中提取这些数据,并在那里显示,如下面的代码所示 test1.aspx 所以,请指导我,我如何可以重定向用户编程到贝宝网站连同数据作为结果,当贝宝网站将在浏览器中打开,然后客户详细信息将填写在那里。再次提到,我需要从代码隐藏以编程方式完

我的情况是这样的,我必须重定向用户到贝宝网站的数据作为结果,当贝宝支付页面将显示,然后用户信息将自动填写。我试过了,但失败了。在本地,我试图模拟代码的问题

test.aspx 上面的代码将用户重定向到test1.aspx页面以及数据

我试图从test1.aspx页面中提取这些数据,并在那里显示,如下面的代码所示

test1.aspx 所以,请指导我,我如何可以重定向用户编程到贝宝网站连同数据作为结果,当贝宝网站将在浏览器中打开,然后客户详细信息将填写在那里。再次提到,我需要从代码隐藏以编程方式完成整个工作。谢谢

这是我得到的解决方案,它更好
使用系统;
使用系统数据;
使用系统配置;
使用System.Linq;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.HTMLControl;
使用System.Web.UI.WebControl;
使用System.Web.UI.WebControl.WebParts;
使用System.Xml.Linq;
Net系统;
使用System.Collections.Specialized;
使用系统文本;
公共静态类HttpHelper
{
/// 
///此方法准备一个Html表单,该表单保存表单提交脚本中添加的隐藏字段中的所有数据。
/// 
///发布和重定向将发生的目标Url,该Url可以位于同一应用程序中,也可以位于应用程序外部。
///将发布到目标Url的数据集合。
///返回过帐表单的字符串表示形式。
///萨梅尔·阿布·拉比
私有静态字符串PreparePOSTForm(字符串url、NameValueCollection数据)
{
//设置窗体的名称
字符串formID=“PostForm”;
//使用要发布的指定数据生成表单。
StringBuilder strForm=新建StringBuilder();
strForm.Append(“”);
foreach(数据中的字符串键)
{
格式追加(“”);
}
格式追加(“”);
//构建执行发布操作的JavaScript。
StringBuilder strScript=新建StringBuilder();
strScript.Append(“”);
附加(“var v”+formID+”=文档“+formID+”;”);
strScript.Append(“v”+formID+”.submit();”;
strScript.Append(“”);
//返回连接的表单和脚本。(顺序很重要,表单然后是JavaScript)
返回strForm.ToString()+strScript.ToString();
}
公共静态void RedirectAndPOST(页面、字符串destinationUrl、NameValueCollection数据)
{
//准备投寄表格
字符串strForm=PreparePOSTForm(destinationUrl,数据);
//在包含Post表单的指定页面中添加文字控件,这是为了随请求提交Post表单。
添加(新的LiteralControl(strForm));
}
}

这是我过去多次使用c#net进行远程发布的代码

我不确定该将代码授权给谁,因为它不是我的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;
using System.Net;


/// <summary>
/// Summary description for RemotePost
/// </summary>
public partial class RemotePost
{
    private NameValueCollection inputValues;

    /// <summary>
    /// Gets or sets a remote URL
    /// </summary>
    public string Url { get; set; }

    /// <summary>
    /// Gets or sets a method
    /// </summary>
    public string Method { get; set; }

    /// <summary>
    /// Gets or sets a form name
    /// </summary>
    public string FormName { get; set; }

    public NameValueCollection Params
    {
        get
        {
            return inputValues;
        }
    }

    /// <summary>
    /// Creates a new instance of the RemotePost class
    /// </summary>
    public RemotePost()
    {
        inputValues = new NameValueCollection();
        Url = "http://www.someurl.com";
        Method = "post";
        FormName = "formName";
    }

    /// <summary>
    /// Adds the specified key and value to the dictionary (to be posted).
    /// </summary>
    /// <param name="name">The key of the element to add</param>
    /// <param name="value">The value of the element to add.</param>
    public void Add(string name, string value)
    {
        inputValues.Add(name, value);
    }


    /// <summary>
    /// Post
    /// </summary>
    public void Post()
    {
        var context = HttpContext.Current;
        context.Response.Clear();
        context.Response.Write("<html><head>");
        context.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
        context.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
        for (int i = 0; i < inputValues.Keys.Count; i++)
            context.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", HttpUtility.HtmlEncode(inputValues.Keys[i]), HttpUtility.HtmlEncode(inputValues[inputValues.Keys[i]])));
        context.Response.Write("</form>");
        context.Response.Write("</body></html>");
        context.Response.End();
    }

}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Collections.Specialized;
Net系统;
/// 
///RemotePost的摘要说明
/// 
公共部分类RemotePost
{
私有名称值集合输入值;
/// 
///获取或设置远程URL
/// 
公共字符串Url{get;set;}
/// 
///获取或设置一个方法
/// 
公共字符串方法{get;set;}
/// 
///获取或设置窗体名称
/// 
公共字符串FormName{get;set;}
public NameValueCollection参数
{
得到
{
返回输入值;
}
}
/// 
///创建RemotePost类的新实例
/// 
公共远程邮政()
{
inputValues=新的NameValueCollection();
Url=”http://www.someurl.com";
方法=“post”;
FormName=“FormName”;
}
/// 
///将指定的键和值添加到字典(要发布)。
/// 
///要添加的元素的键
///要添加的元素的值。
公共void添加(字符串名称、字符串值)
{
输入值。添加(名称、值);
}
/// 
///职位
/// 
公共空缺职位()
{
var context=HttpContext.Current;
context.Response.Clear();
context.Response.Write(“”);
context.Response.Write(string.Format(“,FormName));
Write(string.Format(“,FormName,Method,Url));
对于(int i=0;i
那么你可以简单地称之为


RemotePost-myPost=new-RemotePost('www.paypal.com')
etc

这是我过去多次使用c#net进行远程发布的代码

我不确定该将代码授权给谁,因为它不是我的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;
using System.Net;


/// <summary>
/// Summary description for RemotePost
/// </summary>
public partial class RemotePost
{
    private NameValueCollection inputValues;

    /// <summary>
    /// Gets or sets a remote URL
    /// </summary>
    public string Url { get; set; }

    /// <summary>
    /// Gets or sets a method
    /// </summary>
    public string Method { get; set; }

    /// <summary>
    /// Gets or sets a form name
    /// </summary>
    public string FormName { get; set; }

    public NameValueCollection Params
    {
        get
        {
            return inputValues;
        }
    }

    /// <summary>
    /// Creates a new instance of the RemotePost class
    /// </summary>
    public RemotePost()
    {
        inputValues = new NameValueCollection();
        Url = "http://www.someurl.com";
        Method = "post";
        FormName = "formName";
    }

    /// <summary>
    /// Adds the specified key and value to the dictionary (to be posted).
    /// </summary>
    /// <param name="name">The key of the element to add</param>
    /// <param name="value">The value of the element to add.</param>
    public void Add(string name, string value)
    {
        inputValues.Add(name, value);
    }


    /// <summary>
    /// Post
    /// </summary>
    public void Post()
    {
        var context = HttpContext.Current;
        context.Response.Clear();
        context.Response.Write("<html><head>");
        context.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
        context.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
        for (int i = 0; i < inputValues.Keys.Count; i++)
            context.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", HttpUtility.HtmlEncode(inputValues.Keys[i]), HttpUtility.HtmlEncode(inputValues[inputValues.Keys[i]])));
        context.Response.Write("</form>");
        context.Response.Write("</body></html>");
        context.Response.End();
    }

}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Collections.Specialized;
Net系统;
/// 
///RemotePost的摘要说明
/// 
公共部分类RemotePost
{
私有名称值集合输入值;
/// 
///获取或设置远程URL
/// 
公共字符串Url{get;set;}
/// 
///获取或设置一个方法
/// 
公共字符串方法{get;set;}
/// 
///获取或设置窗体名称
/// 
公共字符串FormName{get;set;}
public NameValueCollection参数
{
得到
{
返回输入值;
}
}
/// 
///创建RemotePost类的新实例
/// 
公共远程邮政()
{
inputValues=新的NameValueCollection();
Url=”http://www.someurl.com";
方法=“post”;
FormName=”
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Collections.Specialized;
using System.Text;

public static class HttpHelper
{
/// <summary>
/// This method prepares an Html form which holds all data in hidden field in the addetion to form submitting script.
/// </summary>
/// <param name="url">The destination Url to which the post and redirection will occur, the Url can be in the same App or ouside the App.</param>
/// <param name="data">A collection of data that will be posted to the destination Url.</param>
/// <returns>Returns a string representation of the Posting form.</returns>
/// <Author>Samer Abu Rabie</Author>

private static String PreparePOSTForm(string url, NameValueCollection data)
{
    //Set a name for the form
    string formID = "PostForm";

    //Build the form using the specified data to be posted.
    StringBuilder strForm = new StringBuilder();
    strForm.Append("<form id=\"" + formID + "\" name=\"" + formID + "\" action=\"" + url + "\" method=\"POST\">");
    foreach (string key in data)
    {
        strForm.Append("<input type=\"hidden\" name=\"" + key + "\" value=\"" + data[key] + "\">");
    }
    strForm.Append("</form>");

    //Build the JavaScript which will do the Posting operation.
    StringBuilder strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var v" + formID + " = document." + formID + ";");
    strScript.Append("v" + formID + ".submit();");
    strScript.Append("</script>");

    //Return the form and the script concatenated. (The order is important, Form then JavaScript)
    return strForm.ToString() + strScript.ToString();
 }

public static void RedirectAndPOST(Page page, string destinationUrl, NameValueCollection data)
{
    //Prepare the Posting form
    string strForm = PreparePOSTForm(destinationUrl, data);

    //Add a literal control the specified page holding the Post Form, this is to submit the Posting form with the request.
    page.Controls.Add(new LiteralControl(strForm));
}

}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;
using System.Net;


/// <summary>
/// Summary description for RemotePost
/// </summary>
public partial class RemotePost
{
    private NameValueCollection inputValues;

    /// <summary>
    /// Gets or sets a remote URL
    /// </summary>
    public string Url { get; set; }

    /// <summary>
    /// Gets or sets a method
    /// </summary>
    public string Method { get; set; }

    /// <summary>
    /// Gets or sets a form name
    /// </summary>
    public string FormName { get; set; }

    public NameValueCollection Params
    {
        get
        {
            return inputValues;
        }
    }

    /// <summary>
    /// Creates a new instance of the RemotePost class
    /// </summary>
    public RemotePost()
    {
        inputValues = new NameValueCollection();
        Url = "http://www.someurl.com";
        Method = "post";
        FormName = "formName";
    }

    /// <summary>
    /// Adds the specified key and value to the dictionary (to be posted).
    /// </summary>
    /// <param name="name">The key of the element to add</param>
    /// <param name="value">The value of the element to add.</param>
    public void Add(string name, string value)
    {
        inputValues.Add(name, value);
    }


    /// <summary>
    /// Post
    /// </summary>
    public void Post()
    {
        var context = HttpContext.Current;
        context.Response.Clear();
        context.Response.Write("<html><head>");
        context.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
        context.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
        for (int i = 0; i < inputValues.Keys.Count; i++)
            context.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", HttpUtility.HtmlEncode(inputValues.Keys[i]), HttpUtility.HtmlEncode(inputValues[inputValues.Keys[i]])));
        context.Response.Write("</form>");
        context.Response.Write("</body></html>");
        context.Response.End();
    }

}