PUT 文件 returned a response status of 403 Forbidden
Posted stk0210
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PUT 文件 returned a response status of 403 Forbidden相关的知识,希望对你有一定的参考价值。
简单来说:文件服务器缺少允许文件读写的配置,直接跳到本帖下面web.xml文件部分,添加配置信息即可解决!
使用springmvc 跨服务器进行文件上传时出现错误:
jersey 上传文件报错出现returned a response status of 403 Forbidden 或returned a response status of 409 Conflict
409错误一般为文件服务器存放文件的目录结构不完整,找不到路径,需要自己进行目录结构完善和补全,即可排查错误。
403错误如下:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:8081/uploads/2cc1ed31ffc1411d9d5808107ae28453_logo.png returned a response status of 403 Forbidden
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:8081/uploads/2cc1ed31ffc1411d9d5808107ae28453_logo.png returned a response status of 403 Forbidden
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause
com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:8081/uploads/2cc1ed31ffc1411d9d5808107ae28453_logo.png returned a response status of 403 Forbidden
原因:
因为所使用的文件服务器,单纯用来存储文件,还未进行其他配置,未配置支持文件写入所以出现问题。
网上搜索之后解决方式为在servlet标签下添加:
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
因为没有进行任何配置,连servlet标签都没有,无法直接添加,所以提供一个相对纯净的模板来提供tomcat服务器针对支持文件写入的配置
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <!--suppress ALL --> <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>readonly</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> </web-app>
添加之后,文件服务器进行正常工作,查看存放目录,文件均正常存储。
以上是关于PUT 文件 returned a response status of 403 Forbidden的主要内容,如果未能解决你的问题,请参考以下文章
springboot 下载模板文件 加载classpath文件路径
python之路_day96_爬虫之requests模块补充