当前位置: 首页 > 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.tj-hxxt.cn/news/34764.html

相关文章:

  • 企业做网站带来的好处seo网站推广下载
  • 做企业内刊有哪些网站推荐制作网页的步骤
  • 用Off做网站北京seo软件
  • 织梦cms零基础做网站百度网站大全
  • 网站开发课程设计参考文献下载应用商店
  • 网站建设需要经历什么步骤网络推广软件免费
  • 郴州网站seo如何免费开自己的网站
  • 电子商务网站建设指导书搜外
  • 深圳住房建设厅网站首页软件开发工具
  • 佛山做网站建设价格中国十大经典广告
  • 公司做的网站费用计入什么科目seo网站关键词优化软件
  • 网站建设云主机云服务器淘宝店铺买卖交易平台
  • 百度网站的网址廊坊优化外包
  • 网站空间地址查询广告推广方案怎么写
  • 移动端web网站百度整站优化
  • 日本做黄视频网站有哪些企业网络营销策划书
  • 网站制作公司源码石家庄seo全网营销
  • 响应试网站和移动端百度网盘客服电话人工服务
  • 网站中的滚动照片怎么做网站后台管理系统
  • 注册销售公司流程和费用资源网站优化排名优化
  • 跨境电商流程seo推广沧州公司电话
  • 网站建设方案 报价微博推广费用一般多少
  • o2o商城分销网站开发从事网络营销的公司
  • 台州市建站公司企业营销策划书范文
  • 淄博网站建设讲解透彻广州seo公司推荐
  • 汽车设计公司排名前十强seo百度站长工具查询
  • logo参考网站域名批量注册查询
  • 门户网站怎样做省好多会员app
  • 安徽平台网站建设费用推广引流渠道有哪些
  • 门户 网站开发周期焊工培训ppt课件