环信调用rest api 返回 远程服务器返回错误: (502) 错误的网关。 大额赏金 求帮忙
错误返回的具体内容
502 Bad Gateway
Powered by Tengine/2.2.0
执行调用的c#接口
public class RestClient
{
public string EndPoint { get; set; }
public HttpVerb Method { get; set; }
public string ContentType { get; set; }
public string PostData { get; set; }
public RestClient()
{
EndPoint = "";
Method = HttpVerb.GET;
ContentType = "application/x-www-form-urlencoded";
PostData = "";
}
public RestClient(string endpoint)
{
EndPoint = endpoint;
Method = HttpVerb.GET;
ContentType = "application/x-www-form-urlencoded";
PostData = "";
}
public RestClient(string endpoint, HttpVerb method)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/x-www-form-urlencoded";
PostData = "";
}
public RestClient(string endpoint, HttpVerb method, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/x-www-form-urlencoded";
PostData = postData;
}
long k = 0;
public string MakeRequest(string token)
{
if (k > 90000) { k = 0; }
k++;
return MakeRequest(""+k, token);
}
public string MakeRequest(string parameters,string token)
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
if(token.Length>0)
{
request.Headers["Authorization"] = "Bearer " + token;
}
request.Method = Method.ToString();
request.ContentLength = 0;
request.ContentType = ContentType;
request.Timeout = 2000;
request.ReadWriteTimeout = 1000;
if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.POST)
{
var encoding = new UTF8Encoding();
var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
request.ContentLength = bytes.Length;
using (var writeStream = request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;
if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
}
}
** 有做parameters自增加来区分缓存
502 Bad Gateway
The proxy server received an invalid response from an upstream server. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!
URL: | http://a1.easemob.com:81/1139161222115946/mygamebox/message/ |
Server: | ops-ali-hk-proxy1 |
Date: | 2017/04/02 00:30:52 |
Powered by Tengine/2.2.0
执行调用的c#接口
public class RestClient
{
public string EndPoint { get; set; }
public HttpVerb Method { get; set; }
public string ContentType { get; set; }
public string PostData { get; set; }
public RestClient()
{
EndPoint = "";
Method = HttpVerb.GET;
ContentType = "application/x-www-form-urlencoded";
PostData = "";
}
public RestClient(string endpoint)
{
EndPoint = endpoint;
Method = HttpVerb.GET;
ContentType = "application/x-www-form-urlencoded";
PostData = "";
}
public RestClient(string endpoint, HttpVerb method)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/x-www-form-urlencoded";
PostData = "";
}
public RestClient(string endpoint, HttpVerb method, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/x-www-form-urlencoded";
PostData = postData;
}
long k = 0;
public string MakeRequest(string token)
{
if (k > 90000) { k = 0; }
k++;
return MakeRequest(""+k, token);
}
public string MakeRequest(string parameters,string token)
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
if(token.Length>0)
{
request.Headers["Authorization"] = "Bearer " + token;
}
request.Method = Method.ToString();
request.ContentLength = 0;
request.ContentType = ContentType;
request.Timeout = 2000;
request.ReadWriteTimeout = 1000;
if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.POST)
{
var encoding = new UTF8Encoding();
var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
request.ContentLength = bytes.Length;
using (var writeStream = request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;
if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
}
}
** 有做parameters自增加来区分缓存
没有找到相关结果
已邀请:
3 个回复
冰莲花
具体问题是网关节点不稳定造成的 我现在的解决方案是 用国内的节点做一个代理ip 每次尝试出错后 转到代理ip转包发送 这样就能解决 在某些时段持续报502 的错误
木云落
Su Xingyu - Easemob member