2
我想从我的C#应用程序调用该API时: https://ocr.space/OCRAPI“没有文件上传或网址提供的”调用API ocr.space
当我把它卷曲,它只是正常工作:
curl -k --form "[email protected]" --form "apikey=helloworld" --form "language=eng" https://api.ocr.space/Parse/Image
我实现了这种方式:
[TestMethod]
public async Task Test_Curl_Call()
{
var client = new HttpClient();
String cur_dir = Directory.GetCurrentDirectory();
// Create the HttpContent for the form to be posted.
var requestContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>( "file", "@filename.jpg"), //I also tried "filename.jpg"
new KeyValuePair<string, string>( "apikey", "helloworld"),
new KeyValuePair<string, string>("language", "eng")});
// Get the response.
HttpResponseMessage response = await client.PostAsync(
"https://api.ocr.space/Parse/Image",
requestContent);
// Get the response content.
HttpContent responseContent = response.Content;
// Get the stream of the content.
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
// Write the output.
String result = await reader.ReadToEndAsync();
Console.WriteLine(result);
}
}
我得到这样的回答:
{
"ParsedResults":null,
"OCRExitCode":99,
"IsErroredOnProcessing":true,
"ErrorMessage":"No file uploaded or URL provided",
"ErrorDetails":"",
"ProcessingTimeInMilliseconds":"0"
}
任何线索?
"[email protected]"
中的@字符是什么?
我把我的filename.jpg文件放在项目和 test project bin/debug目录下,并在调试模式下运行我的测试项目。
所以我不认为错误指向的文件不在预期的位置。 我宁愿怀疑我的代码中有语法错误。
这就像一个魅力。我从中学到了很多,谢谢Nate。 –
@AD没问题! –