简体   繁体   English

使用RestSharp(在IIS中)时无响应结果

[英]No response result when using RestSharp(in IIS)

This problem puzzle me so long time. 这个问题困扰了我这么长时间。

I write an asp.net project, and I use RestSharp to post my request to authorize whether user can log in the site. 我编写了一个asp.net项目,并使用RestSharp发布了我的请求以授权用户是否可以登录该站点。

Below is the code of the method of to call the authorize server 下面是调用授权服务器的方法的代码

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;
}

And this is the address const of my authorize server: 这是我的授权服务器的地址常量:

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

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

When I use these codes in my local environment, I can get the right UserInfo, but when I publish this project to IIS server, I always get 500 code when I call this method. 当我在本地环境中使用这些代码时,可以获得正确的UserInfo,但是当我将该项目发布到IIS服务器时,调用此方法时,我总是得到500个代码。

The error is "response?.Data" is null. 错误是“ response?.Data”为空。

I want to solve this problem and I tried so many ways.But all failed. 我想解决这个问题,尝试了很多方法,但是都失败了。

I want get the reason in the IIS so I added one line code 我想在IIS中得到原因,所以我添加了一行代码

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

It's so amazing that when I open the fiddler, sometimes I can get the UserInfo, but when I close fiddler, the error appeared again. 令人惊奇的是,当我打开提琴手时,有时可以获取UserInfo,但是当我关闭提琴手时,错误再次出现。

Can you tell me why? 你能告诉我为什么吗?

And How to solve this problem. 以及如何解决这个问题。

Thank you. 谢谢。

Ps I forgot one detail, in the IIS the binding domain of mysite is not below kinds "localhost" or "ip:port". ps我忘记了一个细节,在IIS中,mysite的绑定域不在“ localhost”或“ ip:port”种类之下。

I have an another domain like "hai.xxxxx.co", the address of my site is "hai.xxxxx.co:8088". 我有另一个域,例如“ hai.xxxxx.co”,我的站点地址是“ hai.xxxxx.co:8088”。

Update my the binding config in iis 在IIS中更新我的绑定配置

在此处输入图片说明

I think I know the key of this problem. 我想我知道这个问题的关键。

Because the authorize is not from my service, so I need a reverse proxy. 因为授权不是来自我的服务,所以我需要反向代理。

It's the reason of when I open the fiddle and set proxy in the code, I can't get response normally. 这就是为什么当我在代码中打开小提琴并设置代理时,无法正常获得响应的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM