大佬教程收集整理的这篇文章主要介绍了Access-Control-Allow-Origin angularjs到php,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
本地Web服务器(ApachE)处理一个Web应用程序,我想在其中向远程Web服务器(Lighttpd)发出ajax请求.
var req = { method: 'POST',url: 'http://url/myPHP.PHP',headers: { 'Authorization': 'Basic ' + btoa('username:password'),'Content-Type': 'application/x-www-form-urlencoded' },xhrFields: { withCredentials: true },crossDomain: true,data: xmlString } $http(req).then(function () { console.log("OK!"); });
远程PHP脚本是:
<?PHP echo "You have CORS!"; ?>
401 Unhauthorized XMLhttprequest cAnnot load http://url/myPHP.PHP. 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:8888' is therefore not allowed access. The response had http status code 401.
远程Web服务器具有.htpasswd身份验证模式启用和配置的CORS请求.
setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
server.modules = ( # ... "mod_fastcgi","mod_rewrite","mod_redirect","mod_setenv",## before mod_status "mod_status",# ... )
<?PHP header("Access-Control-Allow-Origin: *"); ?>
我还想补充一点,如果您要发送http basic / digest auth数据,则不能使用通配符作为原点.您必须使用实际的源域
setenv.add-response-header = ( "Access-Control-Allow-Origin" => "example.com" ) setenv.add-response-header = ( "Access-Control-Allow-Credentials" => "true" )
以上是大佬教程为你收集整理的Access-Control-Allow-Origin angularjs到php全部内容,希望文章能够帮你解决Access-Control-Allow-Origin angularjs到php所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。