1

我有一个从其他服务获取数据的 API。以下代码在本地 IIS 上运行良好:

if (model.Phone[0] != '+')
        {
            model.Phone = "+" + model.Phone;
        }

        string data = Newtonsoft.Json.JsonConvert.SerializeObject(new { ID = Guid.NewGuid(), Phone = model.Phone});

        if (!string.IsNullOrEmpty(model.Email))
        {
            data = Newtonsoft.Json.JsonConvert.SerializeObject(new { ID = Guid.NewGuid(), Phone = model.Phone, Email = model.Email });
        }

        logger.Debug("GetDataFromSupplier before try");

        try
        {
            WebRequestHandler handler = new WebRequestHandler();
            X509Certificate2 certificate = GetMyX509Certificate();
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            handler.ClientCertificates.Add(certificate);
            HttpClient client = new HttpClient(handler);
            var content = new StringContent(data, Encoding.UTF8, "application/json");
            var request = client.PostAsync(API_URL, content);
            var result = request.Result;
            return result;
        } catch (Exception ex)
        {
            logger.Debug($"GetDataFromSupplier in catch: {ex.Message}");
            var message = new HttpResponseMessage(HttpStatusCode.BadRequest);
            message.Content = new StringContent(ex.Message);
            return message;
        }

但是在我将此代码部署到 Azure 之后,会话会在这行代码上中断:

WebRequestHandler handler = new WebRequestHandler();

客户端应用程序收到 502 HTTP 错误。我试图增加网络服务器的 RAM。catch 块甚至没有运行。什么会导致这个问题?

4

1 回答 1

1
于 2017-08-26T05:04:56.680 回答