远程服务器返回错误:(500) 内部服务器错误

发布于 2024-11-27 22:58:12 字数 1189 浏览 1 评论 0原文

为什么我收到“远程服务器返回错误:(500) 内部服务器错误。” 这个错误是我的代码,

    public override object Request()
    {
        Response = "";
        RequestTime = DateTime.Now;
        var url = _service.Url;
        HttpWebResponse responseObj = null;
        try
        {
            Uri requestUri = null;
            Uri.TryCreate(url, UriKind.Absolute, out requestUri);



            CredentialCache cc = new CredentialCache();
            NetworkCredential networkCredential = new NetworkCredential("username",
                                         "password", url);
            Uri uri = new Uri(url);
            cc.Add(uri, "Basic", networkCredential);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            request.Proxy = new WebProxy(url);
            request.Credentials = cc;

            request.Method = WebRequestMethods.Http.Post;


            Response = request.GetResponse();


        }
        catch (Exception x)
        {

            Logger.append(x.Message, Logger.ERROR);
        }
        Duration = DateTime.Now.Subtract(RequestTime).TotalMilliseconds;
        return Response;
   }

我直接从浏览器尝试了 url,它正在工作。

why I am getting "The remote server returned an error: (500) Internal Server Error."
this error this my code

    public override object Request()
    {
        Response = "";
        RequestTime = DateTime.Now;
        var url = _service.Url;
        HttpWebResponse responseObj = null;
        try
        {
            Uri requestUri = null;
            Uri.TryCreate(url, UriKind.Absolute, out requestUri);



            CredentialCache cc = new CredentialCache();
            NetworkCredential networkCredential = new NetworkCredential("username",
                                         "password", url);
            Uri uri = new Uri(url);
            cc.Add(uri, "Basic", networkCredential);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            request.Proxy = new WebProxy(url);
            request.Credentials = cc;

            request.Method = WebRequestMethods.Http.Post;


            Response = request.GetResponse();


        }
        catch (Exception x)
        {

            Logger.append(x.Message, Logger.ERROR);
        }
        Duration = DateTime.Now.Subtract(RequestTime).TotalMilliseconds;
        return Response;
   }

I tried the url direct from the browser and it's working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的位置 2024-12-04 22:58:12

如果您只是在浏览器中导航到该 URL,则 httpMethod 将为 GET,但您在代码中将其设置为 Post。这可能就是为什么它可以在浏览器中运行,但不能在你的代码中运行。

我想说你的代码可能没问题,但是该网站是否支持该网址的帖子?

If you simply navigate to the url in a browser, the httpMethod will be GET but you're setting it to Post in your code. That might be why it works in the browser but not you code.

i'd say your code it probably fine, but is the web site supporting posts to that url?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文