关于chrome,Request failed with status code 400问题求助

NullPointer9527 2020-04-20 10:45:55
先表明一下问题,我后端一个springboot小项目,前端是vue+axios 上传excel文件的小功能。

btn1: function (e) {
if (!this.fileUpFlag) {
alert("请正确选择上传文件!");
} else {
this.msg2 = "文件正在解析中请稍等";
let formData = new FormData();
// console.log(this.file)
formData.append('file', this.file);
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
};
axios
.post("/excelUp", formData, config)
.then(response => {this.total = response.data.total;
this.errorIf = response.data.errorIf;
this.successSum = response.data.successSum;
this.errorSum = response.data.errorSum;
this.msg2 = "文件解析完成!上传数据总量:" + this.total + " 成功执行数量:" + this.successSum + " 失败数量:" + this.errorSum
})
.catch(function (error) {
console.log(error)
});
}
e.preventDefault()

}


@ResponseBody
@PostMapping("/excelUp")
public ExcelAnalyzeResult excelUp(@RequestParam("file") MultipartFile multipartFile) {
try {
return rootService.addUserExcel(multipartFile.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}


在本地跑的时候,用chrome和火狐 360安全浏览器测试均无问题。部署到服务器上之后,chrome浏览器出现了问题,火狐和360均无问题。chrome浏览器只有在服务器项目每次启动后,第一次才能顺利上传excel,之后点击十几次偶尔能成功上传解析一次。这是前后端报的错误。
前端:Failed to load resource: the server responded with a status of 400 ()
studentAddByExcel:149 Error: Request failed with status code 400
at e.exports (spread.js:25)
at e.exports (spread.js:25)
at XMLHttpRequest.l.<computed> (spread.js:25)
后端:2020-04-20 22:37:35.064 WARN 4708 --- [-nio-443-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]
搞了一天了 百度也解决不来,求大佬帮忙看看
...全文
4971 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
status code 400
NullPointer9527 2020-04-21
  • 打赏
  • 举报
回复
引用 1 楼 心怀啊 的回复:
去掉你的请求头换成这三个cache: false, processData: false,contentType: false,
在本地测试你的方法也是 三个浏览器均无异常,就是一旦部署到华为的服务器上,chrome浏览器就开始 上传失败,火狐和360均无异常
NullPointer9527 2020-04-21
  • 打赏
  • 举报
回复
引用 1 楼 心怀啊 的回复:
去掉你的请求头换成这三个cache: false, processData: false,contentType: false,
你好,问题还是存在,但还是感谢回复。这是谷歌和火狐的截图,谷歌点个十几次请求能成功一次,这是最让我搞不明白的。
心怀啊 2020-04-21
  • 打赏
  • 举报
回复
去掉你的请求头换成这三个cache: false, processData: false,contentType: false,
SimpleBrowser是专门为自动化任务而设计的一个灵活而直观的浏览器引擎,内置.Net 4 framework。示例代码:class Program {     static void Main(string[] args)     {         var browser = new Browser();         try         {             // log the browser request/response data to files so we can interrogate them in case of an issue with our scraping             browser.RequestLogged  = OnBrowserRequestLogged;             browser.MessageLogged  = new Action(OnBrowserMessageLogged);             // we'll fake the user agent for websites that alter their content for unrecognised browsers             browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";             // browse to GitHub             browser.Navigate("http://github.com/");             if(LastRequestFailed(browser)) return; // always check the last request in case the page failed to load             // click the login link and click it             browser.Log("First we need to log in, so browse to the login page, fill in the login details and submit the form.");             var loginLink = browser.Find("a", FindBy.Text, "Login");             if(!loginLink.Exists)                 browser.Log("Can't find the login link! Perhaps the site is down for maintenance?");             else             {                 loginLink.Click();                 if(LastRequestFailed(browser)) return;                 // fill in the form and click the login button - the fields are easy to locate because they have ID attributes                 browser.Find("login_field").Value = "youremail@domain.com";                 browser.Find("password").Value = "yourpassword";                 browser.Find(ElementType.Button, "name", "commit").Click();                 if(LastRequestFailed(browser)) return;                 // see if the login succeeded - ContainsText() is very forgiving, so don't worry about whitespace, casing, html tags separating the text, etc.                 if(browser.ContainsText("Incorrect login or password"))                 {                     browser.Log("Login failed!", LogMessageType.Error);                 }                 else                 {                     // After logging in, we should check that the page contains elements that we recognise                     if(!browser.ContainsText("Your Repositories"))                         browser.Log("There wasn't the usual login failure message, but the text we normally expect isn't present on the page");                     else                     {                         browser.Log("Your News Feed:");                         // we can use simple jquery selectors, though advanced selectors are yet to be implemented                         foreach(var item in browser.Select("div.news .title"))                             browser.Log("* "   item.Value);                     }                 }             }         }         catch(Exception ex)         {             browser.Log(ex.Message, LogMessageType.Error);             browser.Log(ex.StackTrace, LogMessageType.StackTrace);         }         finally         {             var path = WriteFile("log-"   DateTime.UtcNow.Ticks   ".html", browser.RenderHtmlLogFile("SimpleBrowser Sample - Request Log"));             Process.Start(path);         }     }     static bool LastRequestFailed(Browser browser)     {         if(browser.LastWebException != null)         {             browser.Log("There was an error loading the page: "   browser.LastWebException.Message);             return true;         }         return false;     }     static void OnBrowserMessageLogged(Browser browser, string log)     {         Console.WriteLine(log);     }     static void OnBrowserRequestLogged(Browser req, HttpRequestLog log)     {         Console.WriteLine(" -> "   log.Method   " request to "   log.Url);         Console.WriteLine(" <- Response status code: "   log.ResponseCode);     }     static string WriteFile(string filename, string text)     {         var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"));         if(!dir.Exists) dir.Create();         var path = Path.Combine(dir.FullName, filename);         File.WriteAllText(path, text);         return path;     } }

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧