Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure认知服务{body}示例_C#_Azure Cognitive Services_Form Recognizer - Fatal编程技术网

C# Azure认知服务{body}示例

C# Azure认知服务{body}示例,c#,azure-cognitive-services,form-recognizer,C#,Azure Cognitive Services,Form Recognizer,我一直在使用Azure认知服务,并一直在使用提供的示例代码分析表单。我不确定使用什么代码来填充代码的{body}部分。有人能分享我应该在c#中使用的代码示例吗?我正在使用新的表单识别器API,但是代码将与计算机视觉API相同 我已经能够使用gn Curl成功地完成它,但无法在C中使用它# 这是我试过的 命名空间CSHttpClientSample { 静态类程序 { 静态void Main() { MakeRequest(); Console.WriteLine(“按回车键退出…”); Co

我一直在使用Azure认知服务,并一直在使用提供的示例代码分析表单。我不确定使用什么代码来填充代码的{body}部分。有人能分享我应该在c#中使用的代码示例吗?我正在使用新的表单识别器API,但是代码将与计算机视觉API相同

我已经能够使用gn Curl成功地完成它,但无法在C中使用它#

这是我试过的

命名空间CSHttpClientSample
{
静态类程序
{
静态void Main()
{
MakeRequest();
Console.WriteLine(“按回车键退出…”);
Console.ReadLine();
}
静态异步void MakeRequest()
{
var client=新的HttpClient();
var queryString=HttpUtility.ParseQueryString(string.Empty);
//请求头
Add(“Ocp Apim订阅密钥”,“{Subscription Key}”);
//请求参数
查询字符串[“键”]=“{array}”;
var uri=”https://westus2.api.cognitive.microsoft.com/formrecognizer/v1.0-preview/custom/models/{id}/analyze?+queryString;
HttpResponseMessage响应;
//请求主体
byte[]byteData=Encoding.UTF8.GetBytes(“{body}”);
使用(var内容=新的ByteArrayContent(byteData))
{
content.Headers.ContentType=新的MediaTypeHeaderValue(“<您的内容类型,即应用程序/json>”);
response=wait client.PostAsync(uri、内容);
}
}
}
}   

下面是运行表单识别器认知服务的Python示例代码,我在其中为body标记传递了SAS url:

########### Python Form Recognizer Train #############
from requests import post as http_post

# Endpoint URL
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom"
source = r"<SAS URL>"
headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '<Subscription Key>',
}
url = base_url + "/train" 
body = {"source": source}
try:
    resp = http_post(url = url, json = body, headers = headers)
    print("Response status code: %d" % resp.status_code)
    print("Response body: %s" % resp.json())
except Exception as e:
    print(str(e))

下面是运行表单识别器认知服务的Python示例代码,在该服务中,我为body标记传递了SAS url:

########### Python Form Recognizer Train #############
from requests import post as http_post

# Endpoint URL
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom"
source = r"<SAS URL>"
headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '<Subscription Key>',
}
url = base_url + "/train" 
body = {"source": source}
try:
    resp = http_post(url = url, json = body, headers = headers)
    print("Response status code: %d" % resp.status_code)
    print("Response body: %s" % resp.json())
except Exception as e:
    print(str(e))

你在里面放了什么?新的MediaTypeHeaderValue(“<您的内容类型,即应用程序/json>”);你在里面放了什么?新的MediaTypeHeaderValue(“<您的内容类型,即应用程序/json>”);我在找一个C#中的例子。另外,我不想训练模型,我想提交一份文件进行分析。让我检查一下,会给你回复的。谢谢。我也为女士工作。你可以在我的化名Albird找到我:)当然会联系的。我在找一个C#的例子。另外,我不想训练模型,我想提交一份文件进行分析。让我检查一下,会给你回复的。谢谢。我也为女士工作。你可以在我的化名Albird:)找到我,我一定会联系你的。
namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            MakeRequest();
            Console.WriteLine("Hit ENTER to exit...");
            Console.ReadLine();
        }

        static async void MakeRequest()
        {
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");

            // Request parameters
            queryString["keys"] = "{array}";
            var uri = "https://westus2.api.cognitive.microsoft.com/formrecognizer/v1.0-preview/custom/models/{id}/analyze?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes("{body}");

            using (var content = new ByteArrayContent(byteData))
            {
               content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
               response = await client.PostAsync(uri, content);
            }

        }
    }
}   
########### Python Form Recognizer Train #############
from requests import post as http_post

# Endpoint URL
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom"
source = r"<SAS URL>"
headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '<Subscription Key>',
}
url = base_url + "/train" 
body = {"source": source}
try:
    resp = http_post(url = url, json = body, headers = headers)
    print("Response status code: %d" % resp.status_code)
    print("Response body: %s" % resp.json())
except Exception as e:
    print(str(e))
static byte[] GetImageAsByteArray(string imageFilePath)

        {

            // Open a read-only file stream for the specified file.

            using (FileStream fileStream =

                new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))

            {

                // Read the file's contents into a byte array.

                BinaryReader binaryReader = new BinaryReader(fileStream);

                return binaryReader.ReadBytes((int)fileStream.Length);

            }

        }