Javascript 通过Asp.NET的后台代码将数据发布到另一个域
由于我们无法将数据发布到跨域,我想将数据发布到我的aspx页面,代码隐藏代码将获取数据并提交到跨域(这不是我操作的,因此我没有修改jsonp源代码的权限)同时,我向其传递帖子数据的网站也返回了一个包含购物车信息的cookie,我还需要将其存储在本地浏览器缓存中 你能给我一些关于如何实现这一点的代码吗 谢谢 我所知道的是,我需要使用Javascript 通过Asp.NET的后台代码将数据发布到另一个域,javascript,asp.net,Javascript,Asp.net,由于我们无法将数据发布到跨域,我想将数据发布到我的aspx页面,代码隐藏代码将获取数据并提交到跨域(这不是我操作的,因此我没有修改jsonp源代码的权限)同时,我向其传递帖子数据的网站也返回了一个包含购物车信息的cookie,我还需要将其存储在本地浏览器缓存中 你能给我一些关于如何实现这一点的代码吗 谢谢 我所知道的是,我需要使用WebResponse和WebRequest类来实现此目的。您可以使用: using (var client = new WebClient()) { // D
WebResponse
和WebRequest
类来实现此目的。您可以使用:
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];
}
在这方面,您可以使用:
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];
}