标签: http-status-code-405

ASP.NET MVC:Controller.HandleUnknownAction 404或405?

我重写了ASP.NET MVC的Controller.HandleUnknownAction(string actionName)方法.在未找到操作时以及在不允许HTTP方法时调用它.我该如何区分这两者?我想在找不到动作时返回404,在允许注意方法时返回405.

api rest asp.net-mvc http-status-code-404 http-status-code-405

5
推荐指数
1
解决办法
1765
查看次数

405方法不允许 - 适用于除iOS Safari之外的所有内容

我一直在尝试在AngularJS中创建一个跟踪一些统计数据的应用程序,并允许用户将它们提交到谷歌应用程序脚本以进行进一步处理.一切都在电脑上完美运行.我已经在chrome和firefox中对它进行了测试,但是当我尝试在iPad上提交它时会显示以下错误:

无法加载资源:服务器响应状态为405(方法不允许)

无法加载资源:无法从null发出任何请求.

XMLHttpRequest无法加载https://script.googleusercontent.com/macros/echo?user_content_key=UQXGbRq6...HLV301R.无法从null发出任何请求.

var URL = 'https://script.google.com/macros/s/.../exec';

$http.post(URL,
    $.param({ packet: JSON.stringify($scope.data) }), {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    }
).success(function(data, status) {
    alert(data.packet);
    $scope.rollover();
}).error(function(data, status) {
    console.log(data);
    console.log(status);
    $scope.show_status(data);
});
Run Code Online (Sandbox Code Playgroud)

它在控制台中打印几行.数据行为空白,返回状态为404.

请帮忙!

javascript mobile-safari http-status-code-405 angularjs

5
推荐指数
1
解决办法
2565
查看次数

ASP.NET中CORS的问题

我有这个应用程序,我想在Web.Config中设置我的自定义标题,唉,这并不总是万无一失.

  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Methods" value="*" />
    <add name="Access-Control-Allow-Headers" value="*" />
  </customHeaders>
Run Code Online (Sandbox Code Playgroud)

上面的设置和它的迭代如

  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Methods" value="OPTIONS,GET,PUT,DELETE,POST" />
    <add name="Access-Control-Allow-Headers" value="Authorization,Content-Type" />
  </customHeaders>
Run Code Online (Sandbox Code Playgroud)

在所有场景中都没有为我工作过.到目前为止,这种设置在大约50%的测试机器中起作用,405 Method Not Allowed在其他测试机器中起作用.

替代方法是在WebApiConfig.cs此处设置并取消注释自定义标头Web.config.

//Web API Cross origin requests - Enable
  var cors = new EnableCorsAttribute("*", "*", "*");
  config.EnableCors(cors);
Run Code Online (Sandbox Code Playgroud)

为什么这里有这么多的含糊不清,我怎么知道哪些地方CORS会一直有效?我真的很感兴趣设置CORS,Web.config因为我希望在部署版本中灵活地修改它.

c# asp.net-mvc cors http-status-code-405 asp.net-web-api

5
推荐指数
1
解决办法
6285
查看次数

Ajax POST导致405(方法不允许) - Spring MVC

我试图做一个AJAX调用我的春节控制器/用POST方法的行动,并从服务器返回@ResponseBody的对象.奇怪的情况是它在添加spring安全层后停止工作,之前一切正常.我将尝试解释我解决问题的步骤,然后向您展示代码/捕获/等.

经过一些研究后,我发现了一些答案,说明问题可能与csrf机制有关,所以我禁用了它,但仍然存在问题.(spring-security.xml bellow)

我已经做了一个wireshark捕获来检查请求/响应.我的ajax请求没问题,我的控制器声明没问题,但我不明白为什么,405响应指示> 允许:GET(捕获波纹管)

3.我试图通过浏览器访问我的控制器操作(即发出GET请求),我收到错误HTTP状态405 - 不支持请求方法'GET'!

4.我试图将RequestMapping(方法...)更改为RequestMethod.GET,并且请求到达控制器并且工作正常,但我不希望它在GET方法上工作,我想要一个POST请求.

5.更改了RequestMapping(使用,生成,标题)以接受所有类型的数据,但仍然是405 ...

这真让我抓狂!我发布我的文件,所以你可以检查它们,任何提示将不胜感激.谢谢!(重要说明:这是我的绝望配置)

弹簧security.xml文件

<beans:beans 
     xmlns...(all needed declarations)>

<http pattern="/js/**" security="none" />
<http pattern="/css/**" security="none" />

<!-- enable use-expressions -->
<http auto-config="true" >
    <access-denied-handler error-page="/403" />
    <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
    <intercept-url pattern="/login" access="isAnonymous()" />
    <intercept-url pattern="/403" access="permitAll" />
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />

    <form-login  login-page="/login"
                 username-parameter="email"
                 password-parameter="password"
                 authentication-failure-url="/login?failed" />

    <!--
    <csrf/>
    -->
</http>

 ..... (authentication)  
Run Code Online (Sandbox Code Playgroud)

AdminController.java

@Controller
@RequestMapping("/admin**")
public class AdminController {

    ... (all my autowired beans)

    @RequestMapping(
        value …
Run Code Online (Sandbox Code Playgroud)

ajax post spring-mvc spring-security http-status-code-405

5
推荐指数
1
解决办法
1万
查看次数

Ngrok 在隧道传输我的本地主机时返回 405 错误

我有一个网络应用程序机器人,我想对其进行远程控制,以便一些人可以对其进行测试。我正在使用 Bot Framework Emulator 在本地测试它并且它产生了奇迹,但我完全没有让 ngrok 托管它。

(我实际上使用 ...azurewebsites.net/api/messages 链接我的应用程序在 Azure 中与另一个机器人连接,但我不能使用这个,所以我正在尝试使用 ngrok 为我提供的链接 - 两者我管理的机器人和这个机器人托管在 Azure 中,但我不知道如何使其可用于远程访问)

我正在采取的步骤:

  1. 在 Visual Studio 中部署应用程序,使其在 localhost:3979 上运行;

  2. 使用ngrok 3979 http -host-header=rewrite localhost:3979;在 ngrok 中从外部打开端口

  3. 获取 ngrok 为我提供的转发 URL 之一,例如 https://3d609207.ngrok.io

  4. 在 Bot Framework Emulator 中插入上一个 URL;

  5. 单击连接。

在 ngrok 和 Bot Framework Emulator 中都返回了 me 405 Method Not Allowed

我尝试访问我在 Bot Framework Emulator 中插入的链接,我通常拥有在本地托管我的机器人时会看到的页面:

在此处描述您的机器人以及您的使用条款等。

访问 Bot Framework 以注册您的机器人。注册时,请记住将机器人的端点设置为

https://your_bots_hostname/api/messages

但是我无法在 Bot Framework Emulator 中发送或接收消息。

此外,ngrok 在 HTTP 请求标题下打印: …

remote-access http-tunneling http-status-code-405 ngrok botframework

5
推荐指数
1
解决办法
5176
查看次数

XMLHttpRequest() POST 返回 405 错误;不允许的方法

我的html代码:

    <h2>Please finalize your details</h2>
    <form id="details" method="post" class="form">

        Full name: <strong name="name_1">ABCDEF</strong><br><br>
        ID No:<strong name="org_number_1">123</strong><br><br>
        Mobile No:<strong name="ph_number_1"">1234567890</strong><br><br>
        
        E-mail: <strong name="email_1">ABC@DEF.COM</strong><br><br>
        ID Card: <img src="profile.png" alt="preview" name="image" style="width: 100px; height: 100px;"><br><br>

        <button id="go">It's correct</button>
        
    </form>
Run Code Online (Sandbox Code Playgroud)

我的javascript:

document.getElementById('go').addEventListener('click', submit);
function submit(){

    var nme=document.getElementsByName("name_1")[0].innerHTML;
    var id=document.getElementsByName("org_number_1")[0].innerHTML;
    var phone=document.getElementsByName("ph_number_1")[0].innerHTML;
    var email=document.getElementsByName("email_1")[0].innerHTML;
    var img=document.getElementsByName("image")[0].src;

    const xhr=new XMLHttpRequest();

    xhr.onload=function(){

        const serverResponse=document.getElementById("response");
        serverResponse.innerHTML=this.responseText;
    };

    xhr.open("POST", "database_registration.php");
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send("name="+nme+"&id="+id+"&phone="+phone+"&email="+email+"&img="+img); //this line throws the error "Failed to load resource: the server responded with a status of …
Run Code Online (Sandbox Code Playgroud)

html javascript php xampp http-status-code-405

5
推荐指数
1
解决办法
228
查看次数

FastAPI GET 端点返回“405 method not allowed”响应

FastAPI 中的端点GET返回正确的结果,但405 method not allowedcurl -I使用时返回。所有GET端点都会发生这种情况。因此,应用程序正在运行,但负载均衡器对应用程序的运行状况检查失败。

有什么建议可能是错误的吗?

代码

@app.get('/health')
async def health():
    """
    Returns health status
    """
    return JSONResponse({'status': 'ok'})
Run Code Online (Sandbox Code Playgroud)

结果

curl http://172.xx.xx.xx:8080
Run Code Online (Sandbox Code Playgroud)

返回标头

curl -I http://172.xx.xx.xx:8080
Run Code Online (Sandbox Code Playgroud)

python rest http-status-code-405 fastapi

5
推荐指数
1
解决办法
7068
查看次数

HTTP状态405 - HTTP方法此URL不支持POST

HTTP Status 405 - HTTP method POST is not supported by this URL当我使用下面的代码(下面)时,我收到错误...引起麻烦的线(显然)是getServletContext().getRequestDispatcher("/EditObject?id="+objId).forward(request, response);

package web.objects;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ObjDetailsDao;

@SuppressWarnings("serial")
public class EditObjectText extends HttpServlet {

 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


  int objId = Integer.parseInt(request.getParameter("objId"));
  String text = (String)request.getParameter("description");

  ObjDetailsDao oddao = new ObjDetailsDao();
   try {
oddao.modifyText(text, objId);
 /////////////
    getServletContext().getRequestDispatcher("/EditObject?id="+objId).forward(request, response);
 ////////////
   } catch (SQLException e) {
    // TODO Auto-generated catch block …
Run Code Online (Sandbox Code Playgroud)

java servlets http-status-code-405

4
推荐指数
1
解决办法
3万
查看次数

如何在 Spring boot 应用程序的嵌入式 untertow 中禁用 HTTP TRACE

我的目标是为我的 Spring Boot 应用程序禁用 HTTP TRACE 方法,该应用程序使用嵌入式 undertow。

最好进行有效的 yaml 更改,如果没有,更改代码也可以。理想情况下,最终结果应该是 4xx HTTP 响应代码,并且响应中没有 cookie 值。[spring.mvc.dispatch-trace-request: false 给出 200 OK,所以这对我没有好处。]

打破我的头,不应该这么难!

http-status-code-405 spring-boot undertow http-trace

4
推荐指数
1
解决办法
6138
查看次数

即使使用 CorsLayer,Axum 路由器也拒绝使用 405 进行 CORS 选项预检

fetch在发送a 之前,浏览器将发送一个请求方法OPTIONS来确认 API 将接受来自特定来源的脚本的请求。

\n

Chrome 显示我的 Axum 服务器正在拒绝我客户端的 405 请求。我的路由器如下所示:

\n
let app = Router::new()\n    .layer(TraceLayer::new_for_http())\n    .layer(CorsLayer::permissive())\n    .route("/api", post(server));\n
Run Code Online (Sandbox Code Playgroud)\n

Router::layer表示所有到router的请求都会被layer\xe2\x80\x99s对应的中间件处理。但我不确定它是否发挥了作用。

\n

cors http-status-code-405 rust rust-tower rust-axum

4
推荐指数
1
解决办法
6263
查看次数