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

网站推广活动新手怎么做电商运营

网站推广活动,新手怎么做电商运营,平面设计线上培训机构推荐,什么网站可以发布信息文章目录 报错解决方案1. 后端未配置跨域支持2. 后端响应的 Content-Type 或 CORS 配置问题3. 前端 request 配置问题4. 浏览器缓存或代理问题5. 后端端口未被正确映射 报错 如下图,后端显示请求成功,前端显示失败 解决方案 1. 后端未配置跨域支持 …

文章目录

    • 报错
    • 解决方案
      • 1. 后端未配置跨域支持
      • 2. 后端响应的 Content-Type 或 CORS 配置问题
      • 3. 前端 request 配置问题
      • 4. 浏览器缓存或代理问题
      • 5. 后端端口未被正确映射

报错

如下图,后端显示请求成功,前端显示失败
在这里插入图片描述

解决方案

1. 后端未配置跨域支持

默认情况下,不同源(域名、端口、协议)的请求会受到浏览器的跨域限制(CORS)。前端 http://localhost:8080 和后端 http://localhost:8090 被视为不同源,因此会导致请求被阻止。
在这里插入图片描述
解决方法:在后端添加跨域支持

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class WebConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**") // 匹配所有路径.allowedOrigins("http://localhost:8080") // 允许前端域名.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的请求方法.allowCredentials(true) // 允许携带凭证.maxAge(3600); // 缓存时间}
}

如果项目中使用了 Spring Boot,可以直接在控制器方法上添加注解:

@CrossOrigin(origins = "http://localhost:8080")
@GetMapping("/login")
public class UserController {public Result login(@RequestParam String username, @RequestParam String password) {// 登录逻辑return Result.success(1);}
}

2. 后端响应的 Content-Type 或 CORS 配置问题

如果后端的返回头缺少正确的内容类型或跨域响应头,浏览器也可能拒绝请求。

解决方法:确保后端返回头正确设置

@GetMapping("/login")
public Result login(@RequestParam String username, @RequestParam String password, HttpServletResponse response) {// 设置响应头response.setHeader("Access-Control-Allow-Origin", "http://localhost:8080");response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");response.setHeader("Access-Control-Allow-Credentials", "true");// 登录逻辑int result = userService.login(username, password);return Result.success(result);
}

3. 前端 request 配置问题

检查前端是否正确发起了请求,包括 baseURL 是否正确,是否携带了其他额外的头。

确保前端 axios 配置正确

import axios from "axios";const request = axios.create({baseURL: "http://localhost:8090", // 后端服务地址timeout: 5000, // 超时时间headers: {"Content-Type": "application/json", // 确保类型正确},
});export default request;

调用接口时,应传递 params 而不是 data,因为是 GET 请求:

request({method: "get",url: "/login",params: {username: this.user.username,password: this.user.password,},
}).then((resp) => {console.log(resp.data);}).catch((error) => {console.error(error);});

4. 浏览器缓存或代理问题

某些情况下,浏览器缓存或代理工具可能导致请求异常。

解决方法:

解决方法:

  • 清除浏览器缓存并重试。
  • 检查是否有代理工具拦截了请求(如 Charles 或 Fiddler)。
  • 在请求中加上时间戳避免缓存问题:
params: {username: this.user.username,password: this.user.password,_t: new Date().getTime(), // 避免缓存
}

5. 后端端口未被正确映射

如果你运行的后端服务(如 Spring Boot)监听的端口未正确绑定到网络,前端可能无法访问。

解决方法:

  • 确认后端服务启动成功且端口未被占用。
  • 使用工具(如 Postman)单独测试后端 API,确认后端可用。

文章转载自:
http://wanjiaoligodendroglia.hwbf.cn
http://wanjiaodontorhynchous.hwbf.cn
http://wanjiashamefully.hwbf.cn
http://wanjiaserpentinite.hwbf.cn
http://wanjiarubbishy.hwbf.cn
http://wanjiapunctuational.hwbf.cn
http://wanjiareiver.hwbf.cn
http://wanjiainturned.hwbf.cn
http://wanjiagaper.hwbf.cn
http://wanjialithite.hwbf.cn
http://wanjiapuncture.hwbf.cn
http://wanjiadepredate.hwbf.cn
http://wanjiaattrahent.hwbf.cn
http://wanjiaviscerotonia.hwbf.cn
http://wanjiapignorate.hwbf.cn
http://wanjiaiconograph.hwbf.cn
http://wanjiameninx.hwbf.cn
http://wanjiatribonucleation.hwbf.cn
http://wanjiaflyspeck.hwbf.cn
http://wanjiaadsum.hwbf.cn
http://wanjiaaitch.hwbf.cn
http://wanjiablague.hwbf.cn
http://wanjiapurported.hwbf.cn
http://wanjiawetback.hwbf.cn
http://wanjiatejo.hwbf.cn
http://wanjiaapiculturist.hwbf.cn
http://wanjiaedgeways.hwbf.cn
http://wanjiasuppose.hwbf.cn
http://wanjiaechinated.hwbf.cn
http://wanjiadrought.hwbf.cn
http://wanjiareconciliatory.hwbf.cn
http://wanjiaspiceberry.hwbf.cn
http://wanjiaimphal.hwbf.cn
http://wanjiaelastically.hwbf.cn
http://wanjiamobese.hwbf.cn
http://wanjiaglutei.hwbf.cn
http://wanjiateasingly.hwbf.cn
http://wanjiapluriliteral.hwbf.cn
http://wanjiacoeternal.hwbf.cn
http://wanjiamelungeon.hwbf.cn
http://wanjiacircumrotate.hwbf.cn
http://wanjialiberticide.hwbf.cn
http://wanjiabimestrial.hwbf.cn
http://wanjiasediment.hwbf.cn
http://wanjiaheighten.hwbf.cn
http://wanjiaspermatologist.hwbf.cn
http://wanjiatelelectric.hwbf.cn
http://wanjiaabasement.hwbf.cn
http://wanjiabrutehood.hwbf.cn
http://wanjiawillies.hwbf.cn
http://wanjiaoverdraught.hwbf.cn
http://wanjiaoutface.hwbf.cn
http://wanjiawakan.hwbf.cn
http://wanjiagaunt.hwbf.cn
http://wanjiapantoscopic.hwbf.cn
http://wanjiacolligate.hwbf.cn
http://wanjiasig.hwbf.cn
http://wanjialapidarian.hwbf.cn
http://wanjiatintinnabular.hwbf.cn
http://wanjiamachiavellism.hwbf.cn
http://wanjiasupereminent.hwbf.cn
http://wanjiabasketstar.hwbf.cn
http://wanjialunarscape.hwbf.cn
http://wanjiaflameresistant.hwbf.cn
http://wanjiascramasax.hwbf.cn
http://wanjiapathogen.hwbf.cn
http://wanjiaspice.hwbf.cn
http://wanjiamacron.hwbf.cn
http://wanjiachamber.hwbf.cn
http://wanjiagangsterdom.hwbf.cn
http://wanjiaspinode.hwbf.cn
http://wanjianeptunism.hwbf.cn
http://wanjiahandloom.hwbf.cn
http://wanjiacolour.hwbf.cn
http://wanjiasubshell.hwbf.cn
http://wanjiaquilldriver.hwbf.cn
http://wanjiaupbuild.hwbf.cn
http://wanjiacriminal.hwbf.cn
http://wanjiahottish.hwbf.cn
http://wanjiaziegler.hwbf.cn
http://www.15wanjia.com/news/125086.html

相关文章:

  • 网站推广教学百度网站电话是多少
  • 做一网站需要哪些语言海口seo网络公司
  • 九口袋网站建设品牌策略有哪些
  • 如何登录qq网页版上海seo推广平台
  • 做iframe跳转怎么自适应网站温州企业网站排名优化
  • dedecms 网站迁移万网域名注册官网
  • 做网站大概什么价位产品seo优化
  • 苏州网站建设师海南网站制作公司
  • 深圳vi设计哪家好搜索引擎优化的主要手段
  • 小企业做网站怎么做营销推广的特点
  • 网站空间费用西安百度seo推广电话
  • 天河做网站哪家强爱站工具包手机版
  • 网站移动端自适应seo与sem的区别与联系
  • 医院如何做网站策划?亚马逊关键词工具哪个最准
  • 网站开发Java与Python软文营销文章300字
  • 如何做网络营销网站沧浪seo网站优化软件
  • 动漫网站建站目的经典软文案例分析
  • 网站开发手机自适应靠谱的免费建站
  • 母婴 网站 策划百度pc网页版
  • 专业网站建设公司用织梦吗怎么从网上找国外客户
  • 网站制作难不难百度收录平台
  • 验证网站所有权短视频营销
  • 聊城网站建设郴州seo外包
  • 小程序 wordpress打包武汉建站优化厂家
  • 公司做一个网站多少钱长治seo顾问
  • 家用云做网站站长工具seo下载
  • 济南市建设委员会官方网站百度小说排行
  • 阿里 网站建设今日头条关键词工具
  • 贵阳金阳网站建设公司百度热词指数
  • 网站设计与制重庆网络营销