环信调用rest api 返回 远程服务器返回错误: (502) 错误的网关。 大额赏金 求帮忙

错误返回的具体内容<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<h1>502 Bad Gateway</h1>
<p>The proxy server received an invalid response from an upstream server. Sorry for the inconvenience.<br/>
Please report this message and include the following information to us.<br/>
Thank you very much!</p>
<table>
<tr>
<td>URL:</td>
<td>http://a1.easemob.com:81/11391 ... gt%3B
</tr>
<tr>
<td>Server:</td>
<td>ops-ali-hk-proxy1</td>
</tr>
<tr>
<td>Date:</td>
<td>2017/04/02 00:30:52</td>
</tr>
</table>
<hr/>Powered by Tengine/2.2.0</body>
</html>
 
执行调用的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自增加来区分缓存
 
 
 
 
 
已邀请:

冰莲花

赞同来自:

问题解决了 我测试了 香港 美国 韩国 国内华为的 多个服务器及ip段  海外的三个服务器都会报 502 和 timeout 
具体问题是网关节点不稳定造成的  我现在的解决方案是 用国内的节点做一个代理ip 每次尝试出错后 转到代理ip转包发送 这样就能解决 在某些时段持续报502 的错误

木云落

赞同来自:

你调用的是哪个api ?  把完整的url发下

Su Xingyu - Easemob member

赞同来自:

请问发起调用的 IP 是在哪里?我看调用被指向到海外代理节点上了。

要回复问题请先登录注册

知识价值的认可,源自您的赞赏

扫描二维码,你的支付将由imGeek代收后转给对方

×