API 调用以分析自定义表单

API call to analyze a custom form

我正在尝试 API 调用 Microsoft 的表单识别器来根据自定义模型分析表单,但我不知道该怎么做。

这是关于 API

的文档

https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api/operations/AnalyzeWithCustomModel

请求正文是空白的,我真的不知道应该如何格式化才能发送。

如果您查看 POST 训练模型方法,我可以使用该请求正文发送 api 调用。这表明问题出在我身上,而不是 API.

我已经通过命令行使用 curl 成功地完成了这个...

curl -X POST "https://formrecognizerbp.cognitiveservices.azure.com/formrecognizer/v1.0-preview/custom/models/[MODEL ID]/analyze" -H "Content-Type: multipart/form-data" -F "form=@\"C:\Temp\Capture1.jpg\";类型=image/jpeg" -H "Ocp-Apim-Subscription-Key: [SUBSCRIPTION ID]"

我真的不明白 know/can 不知道如何将其转换为格式类似于 POST 训练模型方法的请求正文。

我一直收到这个错误,因为我不知道如何正确格式化请求。

内部:意外错误 Web API HTTP 请求期间出错 HTTP 状态代码:400 HTTP 响应内容:{"value":{"error":{"code":"BadRequest","message":"Could not process incoming request: 'Missing content-type boundary.'. Please ensure that it is well-formed."}},"formatters" :[],"contentTypes":[],"statusCode":400}

所以我猜格式化程序和 contentTypes 是缺失的部分,但那只是文件路径和 curl 的 image/jpeg 部分吗?

/trainCustomModel API expects the data to be present on the Azure Blob storage. The request body to this request needs to contain a valid SAS URL to the training data. Once you successfully create a custom trained model ID, you could use that to analyze the forms. The /AnalyzeWithCustomModel API 期望数据位于您的本地文件存储中。请确保您已正确替换 ModelId、API 订阅密钥(注意这与订阅 ID 不同)和图像的本地路径。

问题是我没有意识到 curl 脚本正在用 image/jpeg 覆盖 multipart/form-data Content-Type,当我试图以不同的方式构建这个调用时,我强制使用 multipart/form-data Content-Type 什么是jpeg。