0
我有一個從其他服務獲取數據的API。下面的代碼工作在本地IIS很大:由於WebRequestHandler部署到Azure後,Web應用程序崩潰
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塊甚至沒有運行。什麼會導致這個問題?
最好使用像wireshark或提琴手嗅探器。比較來自本地IIS的http消息和失敗的消息。比較工作與非工作之間的標題。異常被捕獲到另一個處理程序或是一個Windows 32方法,並且您需要獲取最後一個窗口錯誤。 – jdweng