简体   繁体   English

如何解决 502 Bad Gateway 错误

[英]How to troubleshoot 502 Bad Gateway error

I have我有

curl --include --request POST --header "Content-Type: application/x-www-form-urlencoded" --data-binary "username=xx@xxtemple.net&password=XXXXXXXX" 'https://api.xxsuccess.com/v1/auth' 

running without ANY errors and go what I want.运行没有任何错误,然后去我想要的。

When I run the following C# code on the SAME machine , I got 502 Bad Gateway Error:当我在同一台机器上运行以下 C# 代码时,出现 502 Bad Gateway 错误:

string requestUri = "https://api.xxsuccess.com";
var client = new RestClient(requestUri);
client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator("xx@xxtemple.net", "XXXXX");
var request = new RestRequest("v1/auth", Method.POST);
IRestResponse restResponse = client.Execute(request);

Any idea how troubleshoot the problem ?知道如何解决问题吗? Why "Curl" is working and the code is not.为什么“Curl”有效而代码无效。

--data-binary does POST the data (in this case your username and password) in the request body. --data-binary在请求正文中发布数据(在这种情况下是您的用户名和密码)。 HttpBasic Authentication puts your authentication info into the Authorization header. HttpBasic Authentication 将您的身份验证信息放入Authorization标头中。 So these are different requests.所以这些是不同的要求。

If the first request is working, you need to put the data in the body also for the RestSharp request如果第一个请求正在工作,您还需要将数据放入正文中以用于 RestSharp 请求

var client = new RestClient(requestUri);
var request = new RestRequest("v1/auth", Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("username","yourusername", ParameterType.GetOrPost);
request.AddParameter("password","yourpassword", ParameterType.GetOrPost);

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

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