当前位置: 首页 > news >正文

旅游网站开发百度指数查询官网大数据

旅游网站开发,百度指数查询官网大数据,网站怎么做登录,有没有专门做日本代购的网站背景&#xff1a;我在前端使用vue语言开发的&#xff0c;请求的后端是用ThinkPhp项目开发的。我vue项目里的请求php接口&#xff0c;自带header参数的跨域问题通过网上查询到的server端配置方法已经解决了。我使用的 是中间件的配置方法&#xff1a; <?php//admin 项目 配…

背景:我在前端使用vue语言开发的,请求的后端是用ThinkPhp项目开发的。我vue项目里的请求php接口,自带header参数的跨域问题通过网上查询到的server端配置方法已经解决了。我使用的

是中间件的配置方法:

<?php//admin 项目 配置中间件
use app\admin\middleware\MyCrossDomain;return [MyCrossDomain::class
]; 

 MyCrossDomain.php

<?php
namespace app\admin\middleware;use Closure;
use think\Config;
use think\Request;
use think\Response;/*** 跨域请求支持*/
class MyCrossDomain
{protected $cookieDomain;protected $header = ['Access-Control-Allow-Credentials' => 'true','Access-Control-Max-Age'           => 1800,'Access-Control-Allow-Methods'     => 'GET, POST, PATCH, PUT, DELETE, OPTIONS','Access-Control-Allow-Headers'     => 'Authorization, Code,Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',];public function __construct(Config $config){$this->cookieDomain = $config->get('cookie.domain', '');}/*** 允许跨域请求* @access public* @param Request $request* @param Closure $next* @param array   $header* @return Response*/public function handle(Request $request, Closure $next, array $header = []): Response{$header = !empty($header) ? array_merge($this->header, $header) : $this->header;if (!isset($header['Access-Control-Allow-Origin'])) {$origin = $request->header('origin');if ($origin && ('' == $this->cookieDomain || str_contains($origin, $this->cookieDomain))) {$header['Access-Control-Allow-Origin'] = $origin;} else {$header['Access-Control-Allow-Origin'] = '*';}}return $next($request)->header($header);}
}

这样之后前端项目通过axios接口请求不再报跨域的错了,这一阶段的问题已经解决。

现在有一个新的问题,我在Thinkphp项目里有一个静态的json文件,H5要通过<link>的方式要请求它。类似这样的:

   document.write("<link rel='manifest' href='https://landpage-server.appboost.co/admin/file/xxxxx/xxxx.json');

虽然我的ThinkPhp项目已经配置了跨域的,但是对于请求这个静态文件还是报跨域的问题。折腾了好久,各种配置还是不行。最后我尝试了一种办法,就是专门写一个Controller来响应静态文件的返回。代码如下:

StaticResourceController.php

<?phpnamespace app\admin\controller;use app\admin\model\LogEvents;
use app\admin\model\PixelInfo;
use app\admin\model\ReleasePlatform;
use app\admin\model\ReleaseUrl;
use app\admin\model\User;
use app\admin\model\Wallet;
use app\admin\model\WalletLog;
use app\BaseController;
use app\Response;
use Ramsey\Uuid\Uuid;
use think\facade\Console;
use think\facade\Db;class StaticResourceController extends MBaseController{public function getManifestJson(){$company_code = input("get.code");$promote_code = input("get.id");// echo root_path();$root =  root_path();$dir = $root ."public/page/";// echo $dir;$content = $this->openFile($dir,$company_code,$promote_code);$obj = json_decode($content);return json($obj, 200);}public function openFile($dir, $company_code,$promote_code){$filePath = $dir.$company_code."/".$promote_code.".json"; // 文件路径$mode = 'r'; // 打开模式$fileHandle = fopen($filePath, $mode);$content = fread($fileHandle, filesize($filePath));if ($fileHandle === false) {die('无法打开文件');}fclose($fileHandle);return $content;}
}

H5端请求是这样的:

   document.write("<link rel='manifest' href='https://landpage-server.appboost.co/admin/staticResource/getManifestJson?code="+$company_code+"&id="+$promote_code+"'>");

谢天谢地,终于不报跨域的问题了,成功拿到了json静态文件。

http://www.dinnco.com/news/26611.html

相关文章:

  • 企业营销网站建设公司哪家好网站维护费一年多少钱
  • 网站大部分都是jsp做的百度客服怎么转人工电话
  • 自己网站做第三方支付网络营销的目的是什么
  • 南昌网站建设模板网络公司西安seo专员
  • 外贸电商独立网站买号链接
  • 网站建设步骤视频教程兰州网络推广
  • 各个国家的google网站可以商用的电视app永久软件
  • 常州网站建设 个人做竞价托管的公司
  • 网站同步微博外链的作用
  • 下载类网站 建设方案北京计算机培训机构前十名
  • 网站制作多少页网店代运营骗局
  • 企业如何找网络公司做网站seo搜索引擎优化技术
  • 深圳网站建设迅美长春seo主管
  • 怀柔区建设委员会网站搜索引擎网站入口
  • 切削工具东莞网站建设视频号广告推广
  • 在网站上做承诺书sem优化公司
  • 做网站的财务会涉及到的科目宁德seo推广
  • 硅谷电视剧他们做的是网站还是软件培训学校管理制度大全
  • DW怎么做招聘网站泸州网站优化推广
  • 推广网站怎么建设seo服务优化
  • 网站程序包括数据库和网页程序seo同行网站
  • 知名网站设计欣赏百度流量
  • 一个人可以做网站软文标题例子
  • 广州建设信息网官方网站seo服务指什么意思
  • 长沙做网站的公司引流推广营销
  • 安卓上搭建wordpress谷歌优化是什么意思
  • 网站建设出售百度推广客户端教程
  • 无备案网站加速软件培训班学费多少
  • 精准营销的作用seo快速优化
  • 电子商务网站制作公司seo网络推广到底是做什么的