c# – 为什么我对Kairos api的REST请求说请求缺少必需的参数?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 为什么我对Kairos api的REST请求说请求缺少必需的参数?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3775字,纯文字阅读大概需要6分钟。
内容图文
我正在尝试连接到kairos api以熟悉它并使用它们的检测功能.
这个api还没有正式的C#库.有一个似乎没有积极维护.
我正在尝试使用RestSharp直接连接.服务器正在接收我的请求,如果我省略app_id和app密钥进行身份验证,就会响应我的预期.所以那部分(添加标题)似乎正在起作用.
添加参数似乎失败了.根据他们的网站:https://www.kairos.com/docs/face-recognition/,唯一需要的参数是带有网址或base64编码照片的“图片”.
我添加了参数:
var imageURL = new Uri("http://media.kairos.com/kairos-elizabeth.jpg");
request.AddParameter("image", "{\"url\":\"" + imageURL + "\"}");
但响应仍然是:“错误代码:1002”,
“消息”:缺少一个或多个必需参数.
我怀疑uri是如何构建的,但是我真的不能把它放在它上面.我复制了语法
request.AddParameter("image", "{\"url\":\"" + imageURL + "\"}");
来自我之前提到的相同的C#SDK.我也试过它:
var imageURL = new Uri("http://media.kairos.com/kairos-elizabeth.jpg");
request.AddParameter("image", imageURL);
没有成功.
谁能帮我?
编辑:
为了清楚起见,完整代码如下所示:
static void Main(string[] args)
{
var client = new RestClient();
client.BaseUrl = new Uri("https://api.kairos.com/");
var request = new RestRequest("detect", Method.POST);
request.AddHeader("Content-Type", "application/JSON");
request.AddHeader("app_id", "MY app ID");
request.AddHeader("app_key", "My app KEY");
var imageURL = new Uri("http://media.kairos.com/kairos-elizabeth.jpg");
request.AddParameter("image", "\"url\":\"" + imageURL + "\"");
request.AddParameter("selector:", "FACE");
request.AddParameter("minHeadScale:", "0.125");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
}
解决方法:
在发送之前,您必须将参数序列化为JSON.
我创建了一个dotnetfiddle来证明这一点:
https://dotnetfiddle.net/VrKZo2
文档不正确,您可以只传递图像字段并使其全部工作.
namespace ConsoleApplication3
{
using System;
using RestSharp;
public class Program
{
public static void Main()
{
string appId = "YOUR APP ID HERE";
string appKey = "YOUR APP KEY HERE";
var client = new RestClient("https://api.kairos.com");
var request = new RestRequest("detect", Method.POST);
// automatically makes the request body serialize as JSON
request.RequestFormat = DataFormat.Json;
request.AddBody(new { image = "http://media.kairos.com/kairos-elizabeth.jpg" });
request.AddHeader("app_id", appId);
request.AddHeader("app_key", appKey);
var response = client.Execute(request);
// handle response however you want, but I'm just going to print it out
Console.WriteLine(response.Content);
}
}
}
当我用appId和appKey设置运行时,我得到了这个内容:
{
"images": [
{
"time": 0.19603,
"status": "Complete",
"file": "face_55b7d7c4d2008.jpg",
"width": 1536,
"height": 2048,
"faces": [
{
"topLeftX": 300,
"topLeftY": 526,
"width": 934,
"height": 934,
"leftEyeCenterX": -1,
"leftEyeCenterY": -1,
"rightEyeCenterX": -1,
"rightEyeCenterY": -1,
"noseTipX": -1,
"noseTipY": -1,
"noseBtwEyesX": -1,
"noseBtwEyesY": -1,
"chinTipX": -1,
"chinTipY": -1,
"leftEyeCornerLeftX": -1,
"leftEyeCornerLeftY": -1,
"leftEyeCornerRightX": -1,
"leftEyeCornerRightY": -1,
"rightEyeCornerLeftX": -1,
"rightEyeCornerLeftY": -1,
"rightEyeCornerRightX": -1,
"rightEyeCornerRightY": -1,
"rightEarTragusX": -1,
"rightEarTragusY": -1,
"leftEarTragusX": -1,
"leftEarTragusY": -1,
"leftEyeBrowLeftX": -1,
"leftEyeBrowLeftY": -1,
"leftEyeBrowMiddleX": -1,
"leftEyeBrowMiddleY": -1,
"leftEyeBrowRightX": -1,
"leftEyeBrowRightY": -1,
"rightEyeBrowLeftX": -1,
"rightEyeBrowLeftY": -1,
"rightEyeBrowMiddleX": -1,
"rightEyeBrowMiddleY": -1,
"rightEyeBrowRightX": -1,
"rightEyeBrowRightY": -1,
"nostrilLeftHoleBottomX": -1,
"nostrilLeftHoleBottomY": -1,
"nostrilRightHoleBottomX": -1,
"nostrilRightHoleBottomY": -1,
"nostrilLeftSideX": -1,
"nostrilLeftSideY": -1,
"nostrilRightSideX": -1,
"nostrilRightSideY": -1,
"lipCornerLeftX": -1,
"lipCornerLeftY": -1,
"lipLineMiddleX": -1,
"lipLineMiddleY": -1,
"lipCornerRightX": -1,
"lipCornerRightY": -1,
"pitch": -1,
"yaw": -1,
"roll": -1
}
]
}
]
}
内容总结
以上是互联网集市为您收集整理的c# – 为什么我对Kairos api的REST请求说请求缺少必需的参数?全部内容,希望文章能够帮你解决c# – 为什么我对Kairos api的REST请求说请求缺少必需的参数?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。