这是我在Android上尝试比较两张脸是否属于同一个人的方法。我还在最后展示了我的错误代码。这与 API 有关吗?
try {
URL url = new URL("https://southeastasia.api.cognitive.microsoft.com/face/v1.0/verify?faceId1=" + face1 + "&faceId2=" + face2);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Ocp-Apim-Subscription-Key", "----");
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append("n");
}
bufferedReader.close();
getting = stringBuilder.toString();
Log.v("Gettinganswer", getting);
return getting;
} finally {
urlConnection.disconnect();
}
}
catch(Exception e) {
Log.e("ERROR", e.getMessage(), e);
return null;
}
2018-10-24 23:45:44.200 25987-26725/com.example.android.staysaferesq E/ERROR: https://southeastasia.api.cognitive.microsoft.com/face/v1.0/verify?faceId1=03ab5c58-86bb-4eef-a89e-56d4ce76e95b&faceId2=03ab5c58-86bb-4eef-a89e-56d4ce76e95b
java.io.FileNotFoundException: https://southeastasia.api.cognitive.microsoft.com/face/v1.0/verify?faceId1=03ab5c58-86bb-4eef-a89e-56d4ce76e95b&faceId2=03ab5c58-86bb-4eef-a89e-56d4ce76e95b
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
at com.example.android.staysaferesq.FaceActivity$RetrieveFeedTask.doInBackground(FaceActivity.java:301)
at com.example.android.staysaferesq.FaceActivity$RetrieveFeedTask.doInBackground(FaceActivity.java:275)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
这与 API 有关吗?
根据文档,我们可以知道人脸验证API端点应该是
post https://[location].api.cognitive.microsoft.com/face/v1.0/verify
正文格式为
{
"faceId1": "xxxxxxxx",
"faceId2": "xxxxx",
}