简体   繁体   English

是否可以在JavaScript POST请求中将Cookie设置到外部站点?

[英]Can I set cookies in JavaScript POST-request to the external site?

Subj. 主题 More detailed: 更详细:

If I have JS-code on the page, loaded from my site, can that code make POST-request to the third site and set up cookies for that request? 如果页面上有从我的网站加载的JS代码,那么该代码可以对第三个站点进行POST请求并为该请求设置Cookie吗?

Or more commonly - can I set up arbitrary headers (including cookies) in the JavaScript POST-request to the third-party site? 或更常见的是-我可以在对第三方站点的JavaScript POST请求中设置任意标头(包括cookie)吗?

For security reasons that's not possible 出于安全原因,这是不可能的

You can have a hidden iframe tag into your html, but you can't access the cookies that the site saves into the browser 您可以在HTML中添加一个隐藏的iframe代码,但无法访问该网站保存在浏览器中的cookie

<?php

$var=$_COOKIE['somevar'];
?>
<iframe src="http://www.someurl.com/somefile?variable=<?php echo $var?>" style="display:none" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM