[英]Azure Face Detect API - An Error occurred while sending the request
我正在使用 Azure 認知服務在我的 ASP.NET MVC web 應用程序中檢測圖像中的人臉。 但它的“DetectWithStreamAsync”總是拋出“發送請求時發生錯誤”。 我從這個項目https://github.com/Azure-Samples/Cognitive-Face-CSharp-sample中引用了 WPF 應用程序。 但是,當我使用相同的代碼、訂閱密鑰和端點 URL 時,此 WPF 應用程序不會引發相同的異常。 僅當 MVC 應用程序發出請求時才會引發異常。
編輯:我也嘗試過使用 Microsoft.ProjectOxford.Face 的“DetectAsync”方法,但遇到了同樣的異常。
我的代碼如下:
using Microsoft.Azure.CognitiveServices.Vision.Face;
using Microsoft.Azure.CognitiveServices.Vision.Face.Models;
namespace MyApplication.FaceRecognition
{
public class FaceRecognitionService
{
private static string key =ConfigurationManager.AppSettings["FaceAPIKey"];
private static string endPoint =ConfigurationManager.AppSettings["FaceAPIEndPoint"];
private readonly IFaceClient faceClient = new FaceClient(
new ApiKeyServiceClientCredentials(key),
new System.Net.Http.DelegatingHandler[] { });
public FaceRecognitionService()
{
faceClient.Endpoint = endPoint;
}
public async Task<Guid> DetectFace(string imgPath)
{
Guid faceID = Guid.Empty;
try
{
using (Stream faceimagestream = File.OpenRead(imgPath))
{
var faces = await faceClient.Face.DetectWithStreamAsync(faceimagestream,true,false);
if (faces.Count > 0)
faceID = faces[0].FaceId?? default;
}
return faceID;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
檢查內部異常后,我得到“底層連接已關閉,發送時發生意外錯誤”。 這是由於安全協議問題。原來我的 httpRuntime targetFramework 是 4.5,將其更改為 4.7 或啟用 TLS 1.2 解決了上述錯誤。
@Sanjay 感謝您的解決方案。 4.6版本也足夠了。
我編輯了 web.config 如下所示,它可以工作!
<system.web>
<compilation targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
</system.web>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.