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

旅游网站开发东莞关键词排名提升

旅游网站开发,东莞关键词排名提升,基于django的电子商务网站设计,千阳县住房和城乡建设局网站背景&#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.ds6.com.cn/news/104879.html

相关文章:

  • 北京网站建设seo优化百度推广优化公司
  • 网站开发需要学哪些培训课程安排
  • 网站建设发展历程ppt沧州网站seo
  • 网站建设 柳州百度一下官网首页百度
  • 网站怎么优化排名seo主管招聘
  • 长沙望城区政府门户网站seo程序专员
  • 企业管理软件erp佛山做优化的网络公司
  • 建立独立域名的网站怎样才算是自己的什么是seo文章
  • 苏州新区网站制作建设推南昌百度快速排名提升
  • 美术对网站开发有用吗四川seo推广
  • 磁贴式网站模板打开百度首页
  • 新网站怎么做seo 风享如何注册网站
  • 美的地产集团官方网站建设事件营销的案例有哪些
  • 企业管理六大体系华为seo诊断及优化分析
  • 网站建设 关于我们谷歌seo公司
  • 国内免费顶级域名网站域名关键词查询
  • flash做网站的论文百度2022年版本下载
  • 哪些网站是用asp.net做的日本樱花免m38vcom费vps
  • 天津网站制作西安类似58的推广平台有哪些平台
  • 网站扒下来了怎么做视频号链接怎么获取
  • 注册文化传媒公司流程和费用青岛招聘seo
  • 第一模板网站广安seo外包
  • 上海网站 建设大批量刷关键词排名软件
  • 中国域名管理中心360搜索引擎优化
  • 企业品牌网站建设应该怎么做营销 推广
  • ui设计师是吃青春饭吗杭州seook优屏网络
  • 沙田镇网站仿做武汉seo排名公司
  • web制作网页计算器南宁seo服务公司
  • 偏门赚钱网站网站seo博客
  • 如何评价网站是否做的好坏app拉新项目