这是两个页面,test.php和testserver.php.
test.php的
<script src="scripts/jq.js" type="text/javascript"></script>
<script>
$(function() {
$.ajax({url:"testserver.php",
success:function() {
alert("Success");
},
error:function() {
alert("Error");
},
dataType:"json",
type:"get"
}
)})
</script>
Run Code Online (Sandbox Code Playgroud)
testserver.php
<?php
$arr = array("element1",
"element2",
array("element31","element32"));
$arr['name'] = "response";
echo json_encode($arr);
?>
Run Code Online (Sandbox Code Playgroud)
现在我的问题是:当这两个文件都在同一台服务器(localhost或web服务器)上时,它可以工作并被alert("Success")调用; 如果它位于不同的服务器上,意味着Web服务器上的testserver.php和localhost上的test.php,它就无法工作,并且alert("Error")正在执行.即使ajax中的URL更改为http://domain.com/path/to/file/testserver.php
我正在尝试向WCF服务(我拥有)进行跨域HTTP请求.我已经阅读了几种处理跨域脚本限制的技术.因为我的服务必须同时兼顾GET和POST请求,所以我无法实现一些动态脚本标记,其src是GET请求的URL.由于我可以自由地在服务器上进行更改,因此我开始尝试实施一种解决方法,该方法涉及配置服务器响应,以包含"Access-Control-Allow-Origin"标头和带有OPTIONS请求的"预检"请求.我从这篇文章中得到了一个想法:让CORS正常工作
在服务器端,我的Web方法是在HTTP响应中添加"Access-Control-Allow-Origin:*".我现在可以看到响应包含此标题.我的问题是:我如何"预检"一个请求(OPTIONS)?我正在使用jQuery.getJSON来发出GET请求,但浏览器会立即取消臭名昭着的请求:
Access-Control-Allow-Origin不允许使用origin http:// localhost
有人熟悉这种CORS技术吗?需要在客户端进行哪些更改以预检我的请求?
谢谢!
由于php.net上的SOAP手册不是很友好,我找不到任何好的例子,我会在这里发布我的问题.
如何创建PHP SOAP请求看起来像这样?
POST /MySERVER/myWSDLservice.asmx HTTP/1.1
Host: connection.mywebsite.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://connection.mywebsite.com/MySERVER/GetCarType"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetCarType xmlns="http://connection.mywebsite.com/MySERVER/">
<IDNumber>string</IDNumber>
</GetCarType>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
请注意:
任何建议/链接/示例非常感谢.
我有一个node.js express app,提供RESTful API,我使用护照进行Facebook身份验证.我在服务器端启用了所有CORS配置,并且能够通过jQuery Ajax使用API.但对于Facebook身份验证,我收到以下错误:
XMLHttpRequest cannot load http://localhost:3000/auth/facebook. The request was redirected to 'https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%…_me%2Cuser_checkins%2Cuser_likes&client_id=12345678&type=web_server', which is disallowed for cross-origin requests that require preflight.
Run Code Online (Sandbox Code Playgroud)
/ auth/facebook端点就是这个.
app.get('/auth/facebook',
passport.authenticate('facebook', {
scope: ['email', 'user_about_me', 'user_checkins', 'user_likes'],
failureRedirect: users.authFailCallback
}), users.signin);
Run Code Online (Sandbox Code Playgroud)
所以基本上它被重定向到Facebook的API(302),它不允许CORS.有什么方法可以解决这个问题吗?或者我需要从服务器端调用Facebook API?
redirect cross-domain node.js facebook-graph-api passport.js
我为这两个应用程序添加了SSL.
假设https:// www.a.com和https:// www.b.com.
https:// www.a.com正在通过调用访问wcf服务.我也在使用jsonp这个功能.当这些应用程序不是https时,它工作正常.但是当我将其设为https时,呼叫失败了.它在此次调用中给出了firebug中的"Internel服务器错误".https:// www.b.com$.ajax()$.ajax()$.ajax()
我们可以在安全模式下做这样的事情吗?
这个问题可能听起来像是重复的,但我已经尝试了stackoverflow上其他类似问题的所有步骤,但没有一个有效.我正在尝试使用离子连接到Rails API.
我的设置是Rails 4,设计身份验证,基于令牌的API请求的simple_token_authentication gem和移动应用程序的离子设置.
我可以通过将具有正确用户名和密码的登录请求传递给设计会话控制器api来登录离子,并在成功登录设计api后获取令牌.
之后,当我尝试使用访问令牌使用get查询访问任何控制器的索引时: http:// localhost:3002/api/categories?token = 1098ccee839952491a4或http:// localhost:3002/api/employer?token = 1098ccee839952491a4
响应是设计的sign_in页面.在rails日志中,它显示
Started GET "/api/categories?token=1098ccee839952491a43" for ::1 at 2016-06-17 17:45:55 +0530
Processing by Api::CategoriesController#index as HTML
Parameters: {"token"=>"1098ccee839952491a43"}
User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`authentication_token` = '1098ccee839952491a43'
Completed 401 Unauthorized in 3ms (ActiveRecord: 0.7ms)
Started GET "/users/sign_in" for ::1 at 2016-06-17 17:45:55 +0530
Processing by Devise::SessionsController#new as HTML
Rendered devise/shared/_links.html.erb (6.5ms)
Rendered devise/sessions/new.html.erb within layouts/login (78.3ms)
Completed 200 OK in 3850ms (Views: 3847.1ms …Run Code Online (Sandbox Code Playgroud)