gpt4 book ai didi

ios - OCRApiService.com SDK 问题?

转载 作者:行者123 更新时间:2023-11-29 13:44:14 25 4
gpt4 key购买 nike

我对 OCRApiService.com 提供给开发人员的代码有疑问。

这是他们提供的代码:

//author : Altaf A. M.
//Code Snippet to convert the captured/picker'd (sic) image via OCRApiService
//Input parameter: UIImage
//output parameter: NSString
//updates possible(rather necessary): integrate it asynchronously

- (NSString *) upload:(UIImage *)myImage
{
NSString *urlString = @"http://api.ocrapiservice.com/1.0/rest/ocr";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSMutableData *body = [NSMutableData data];

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];

// file
// NSData *imageData = UIImagePNGRepresentation(myImage);
NSData *imageData = UIImageJPEGRepresentation(myImage, 1.0);
[body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: attachment; name=\"image\"; filename=\".jpg\""] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithString:@""] dataUsingEncoding:NSUTF8StringEncoding]];

// Text parameter1

NSString *param1 = @"en";
[body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"language\""] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:param1] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@""] dataUsingEncoding:NSUTF8StringEncoding]];

// Another text parameter

NSString *param2 = @"YOUR_API_KEY";
[body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"apikey\""] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:param2] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@""] dataUsingEncoding:NSUTF8StringEncoding]];

// close form

[body appendData:[[NSString stringWithFormat:@"--%@--", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

// set request body

[request setHTTPBody:body];

//return and test

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnedString = [[[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding] autorelease];


// NSLog(@"received string = %@", returnString);

// UIAlertView *returnedText = [[UIAlertView alloc] initWithTitle:@"Returned Text" message:[NSString stringWithFormat:@"%@", returnString] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];

// [returnedText show ];

// [returnedText release];

return returnedString;

}

我输入了我的 API key ,但问题是每当我调用此方法时,我都会得到

received string = HTTP/1.1 400 Bad Request
The language parameter is missing

根据文档,我已经正确设置了语言,但我不确定为什么它仍然会出现此错误消息...

谢谢!

最佳答案

我是 ocrapiservice.com 的所有者。

该 API 可以正常工作,但代码片段中存在错误。你能在https://github.com/smart-mobile-software/ocrapiservice/issues上打开一个问题吗? ?

我们将在一周内更正。

关于ios - OCRApiService.com SDK 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com