【问题标题】:No response result when using RestSharp(in IIS)使用 RestSharp 时没有响应结果(在 IIS 中)
【发布时间】:2017-07-02 13:43:05
【问题描述】:

这个问题困扰了我很久。

我写了一个 asp.net 项目,我使用 RestSharp 发布我的请求以授权用户是否可以登录该站点。

下面是调用授权服务器的方法代码

public static async Task<UserInfo> ValidatorResult(string userName, string passWord)
{
    var client = new RestClient(AuthUrl.BaseUrl);
    var request = new RestRequest(AuthUrl.LoginURL, Method.POST);
    //client.Proxy = new WebProxy("127.0.0.1", 8888);
    request.AddParameter(InformationDefine.CLIENT_ID_ID, InformationDefine.CLIENT_ID);
    request.AddParameter(InformationDefine.CLIENT_SECRET_ID, InformationDefine.CLIENT_SECRET);
    request.AddParameter(InformationDefine.GRANT_TYPE_ID, InformationDefine.GRANT_TYPE_PASSWORD);
    request.AddParameter(InformationDefine.MAIL_ID, userName);
    request.AddParameter(InformationDefine.PASSWORD_ID, passWord);
    var response = await client.ExecuteTaskAsync<UserInfo>(request);
    return response?.Data;
}

这是我的授权服务器的地址常量:

class AuthUrl
{
    public const string BaseUrl = @"https://account.mysit.com.cn";

    public const string LoginURL = @"/api/oauth/access";
}

当我在本地环境中使用这些代码时,我可以获得正确的UserInfo,但是当我将此项目发布到IIS服务器时,我调用此方法时总是得到500代码。

错误是“response?.Data”为空。

我想解决这个问题,我尝试了很多方法。但都失败了。

我想在 IIS 中获取原因,所以我添加了一行代码

client.Proxy = new WebProxy("127.0.0.1", 8888);

神奇的是,我打开fiddler时,有时能得到UserInfo,但是当我关闭fiddler时,错误又出现了。

你能告诉我为什么吗?

以及如何解决这个问题。

谢谢。

P.s 我忘了一个细节,在 IIS 中 mysite 的绑定域不在“localhost”或“ip:port”类型之下。

我有另一个域名,例如“hai.xxxxx.co”,我的网站地址是“hai.xxxxx.co:8088”。

在 iis 中更新我的绑定配置

【问题讨论】:

  • 我应该更改 IIS 服务器的配置吗?
  • account.mysit.com.cn 这个域是否位于您的 IIS 中?
  • @ngeksyo 是的,我的网站在这个域下,使用一个端口。
  • 当您在服务器中调用应用程序时,应使用本地地址 (localhost:port) 而不是域。
  • 可能我让你误会了,IIS添加网站可以绑定一个域到一个站点,而我的站点在IIS中,但是域我只知道api地址,不知道它的位置.@ngeksyo

标签: c# asp.net .net asp.net-mvc iis


【解决方案1】:

我想我知道这个问题的关键了。

因为授权不是来自我的服务,所以我需要一个反向代理。

这是我打开fiddle并在代码中设置代理时无法正常响应的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2023-03-10
    相关资源
    最近更新 更多