跨域访问
跨域访问:指的是经过第三方的网页把内容显示到第三方页面上,而数据不经过第三方的服务器;
技术实现:在请求头或者file_get_contents之前添加即可;
注意: header("Access-Control-Allow-Origin:*"); 其中 “*”表示允许所填写的任何URL地址访问。
如果指定URL路由,那么就只能确定一个固定的路径URL访问。
在请求头中添加即可:
$msDealCommon = new MsgDeal();
$postStr = $msDealCommon->file_get_contentsd("php://input");//跨域消息头
class MsgDeal{
/**
* @desc 设置file_get_contents函数的超时时间,防止服务挂掉
* 跨域访问header头添加
*/
public function file_get_contentsd ($url)
{
$http = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : '';
// 响应头设置
header("Access-Control-Allow-Headers:origin, x-csrftoken, x-requested-with,content-type, accept, x-auth-code, X-App-Id, X-Token");