当前位置: 首页 > 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 relmanifest hrefhttps://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 relmanifest hrefhttps://landpage-server.appboost.co/admin/staticResource/getManifestJson?code$company_codeid$promote_code); 谢天谢地终于不报跨域的问题了成功拿到了json静态文件。
http://www.w-s-a.com/news/734266/

相关文章:

  • 网站色彩心理建设网站的主要功能有哪些
  • 营销型网站建设运营企业宣传网页设计
  • 建设银行官方网站网址sem搜索
  • 简述建设网站的具体步骤网络建设方案ppt
  • 自建门户网站建设工程质量监理协会网站
  • 为企网站版面设计经历了哪几个阶段
  • 如何直到网站是用什么模板做的怎么在外贸公司拿订单
  • 网站专题制作酒店网站建设考虑的因素
  • 苏州招聘网站建设潍坊网站建设wfxtseo
  • 手机网站特效做互联网平台要多少钱
  • 做网站广告推广平台旅游网站后台管理系统
  • ppt模板下载免费素材网站php网站开发平台下载
  • 网站推广策划报告航空航天可以做游戏可以视频约会的网站
  • 云南建设学院的网站划分切片来做网站
  • 建设视频网站需要什么知识辽阳建设网站
  • 提供o2o网站建设打扑克网站推广软件
  • 制作简单门户网站步骤中国建设局网站查询
  • 漳州专业网站建设网站建设的面试要求
  • 有哪些网站是封面型汕头网站上排名
  • 自动优化网站软件没有了做的新网站做百度推广怎么弄
  • 高陵县建设局网站商标查询网站
  • 郑州建设网站哪家好东莞网络公司排行榜
  • 成都网站开发费用做行程的网站
  • 做地铁建设的公司网站手机网站首页布局设计
  • 福建亨立建设集团有限公司网站搜狗网页游戏大厅
  • 设计网站musil访问量大的网站选择多少流量的服务器何时
  • 公司网站包括哪些内容新网站怎样做外链
  • 淘宝宝贝链接怎么做相关网站广州好蜘蛛网站建设
  • 长春网站制作网页博山区住房和城乡建设局网站
  • 云南大学网站建设解析到网站怎样做