简体   繁体   English

贝宝访问控制允许来源

[英]Paypal Access-Control-Allow-Origin

I'm trying to learn paypal payment.我正在尝试学习贝宝付款。 I have done a simple AngularJS application that use Paypal-Express-Checkout.我已经完成了一个使用 Paypal-Express-Checkout 的简单 AngularJS 应用程序。 As it says on the documentation, first of all I have to do the call SetExpressCheckout.正如文档中所说,首先我必须调用 SetExpressCheckout。

$http.post("https://api-3t.sandbox.paypal.com/nvp", request)
.success(function(data){
    console.log(data);
}).error(function(error){
    console.log(error);
});

In the object request there are all payment details.在对象request有所有付款详细信息。 But when I run the script, the result of http call is: XMLHttpRequest cannot load https://api-3t.sandbox.paypal.com/nvp. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.但是当我运行脚本时,http调用的结果是: XMLHttpRequest cannot load https://api-3t.sandbox.paypal.com/nvp. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. XMLHttpRequest cannot load https://api-3t.sandbox.paypal.com/nvp. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. I tried to search this error, but I find nothing.我试图搜索此错误,但一无所获。 How can I solve?我该如何解决?

UPDATE: If the request comes from a form does not give me any error but if it come from http.post function it give me an error更新:如果请求来自表单不会给我任何错误,但如果它来自 http.post 函数,它会给我一个错误

You have to perform your Paypal transaction on the back end, and the message you're seeing is Paypal enforcing that notion.您必须在后端执行您的 Paypal 交易,您看到的消息是 Paypal 强制执行该概念。 See this article on CORS for more info.有关详细信息,请参阅有关 CORS 的这篇文章

Your angular http call should be sending the basic transaction info to your server, which will then construct an API request for Paypal, handle the response from Paypal, and then convey that information for consumption by the client side.您的 Angular http 调用应该将基本交易信息发送到您的服务器,然后服务器将为 Paypal 构建 API 请求,处理来自 Paypal 的响应,然后传达该信息以供客户端使用。

[edited to add more info about CORS] [编辑以添加有关 CORS 的更多信息]

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

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