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沒問題! –