通过Asp.NET的代码隐藏将数据发布到另一个域

时间:2010-08-30 19:01:35

标签: javascript asp.net

由于我们无法将数据发布到跨域,我想将数据发布到我的aspx页面,代码隐藏代码将获取数据并提交到跨域(这不是我操作的) ,所以我没有权限修改jsonp的源代码,而且我传递我的帖子数据的网站也返回了一个包含购物车信息的cookie,我需要将它存储在我的本地浏览器上缓存也是如此。

你能提供一些关于如何实现这个目标的代码吗?

谢谢..

我所知道的是,我需要以这种方式使用WebResponseWebRequest类。

1 个答案:

答案 0 :(得分:3)

您可以使用WebClient

using (var client = new WebClient())
{
    // Define data to be posted
    var values = new NameValueCollection
    {
        { "key1", "value1" },
        { "key2", "value2" },
    };

    // Send the POST request
    byte[] result = client.UploadValues("http://foo.com", values);

    // This will contain the cookie being set
    string cookie = client.ResponseHeaders[HttpResponseHeader.SetCookie];
}