什么导致HttpListener HTTP 503错误

本文关键字:错误 HTTP HttpListener 什么 | 更新日期: 2023-09-27 18:14:37

所以,我们有一个大程序,它使用HttpListener实现一个小的远程管理功能。由于我不明白的原因,有些人会遇到503错误的问题。

由于我们没有提供错误,所以框架中发生了一些事情。现在,我的问题是,是什么导致了这个错误?是前缀设置不正确还是怎么的?

我们当前的前缀设置为"http://*:8080/"。

建议吗?

什么导致HttpListener HTTP 503错误

我在Windows 7上也有同样的错误,当试图使用netsh http命令设置HttpListener的权限时。在目标系统上运行命令(适用于Windows 7):

netsh http show urlacl    

和检查,如果您的URL "http://+:8080/"已经出现在保留的URL列表中。尝试从列表中删除(使用"netsh http delete url")。

我回答这个问题有点晚了。但是在以下情况下,我只是面对HTTP 503状态码:

如果,例如,有"http://+:8080/MyService/" "http://+:8080/MyService/SOAP"使用netsh http add urlacl注册,我们收到503的请求针对一个不明确的URL。对"http://myservice:8080/MyService/somethingelse"的请求工作正常,而对"http://myservice:8080/MyService/SOAP/"的请求失败,状态为503。

为了完整性添加了这个。我花了一点时间才明白。

确保您的HttpListenerurlacl匹配。

启动监听器为(c#):

using System;
using System.Net;
using System.ServiceModel;
namespace Example
{
    class MyApi
    {
        private const int _apiPortNumber = 8080;
        public const string BasePath = "/myApi/";
        public static EndpointAddress MyEndPoint => new EndpointAddress(
            new UriBuilder(
                    Uri.UriSchemeHttp,
                    "localhost",//only allow connections on localhost (no remote access)
                    _apiPortNumber,
                    BasePath)
                .Uri);
        public MyApi()
        {
            var httpListener = new System.Net.HttpListener();
            httpListener.Prefixes.Add(MyEndPoint.Uri.ToString());
            httpListener.Start();
        }
    }
}

作为你的urlacl的工作是:

netsh http add urlacl url=http://127.0.0.1:8080/myApi/ user=MyServiceUserName

但是像下面这样配置你的urlacl是行不通的:

http add urlacl url=http://+:8080/myApi/ user=MyServiceUserName