我开发搜索类似图像的程序(反向图像搜索) 我的代码:
Y_request = [[NSMutableURLRequest alloc]init];
[Y_request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[Y_request setHTTPShouldHandleCookies:NO];
[Y_request setTimeoutInterval:30];
[Y_request setHTTPMethod:@"POST"];
NSString *Y_boundary=@"myBoucndary";
NSString *Y_FileParamConstant=@"upfile";
Y_requestURL = [[NSURL alloc]initWithString:@"https://www.yandex.com/images/search"];
NSString *Y_contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",Y_boundary];
[Y_request setValue:Y_contentType forHTTPHeaderField:@"Content-Type"];
Y_body = [NSMutableData data];
NSDictionary *Y_params=@{
@"format":@"",
@"request":@"[{\"block\":\"b-page_type_search-by-image__link\"}]",
@"rpt":@"imageview"
};
for (NSString *Y_param in Y_params) {
[Y_body appendData:[[NSString stringWithFormat:@"--%@\r\n",Y_boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[Y_body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", Y_param] dataUsingEncoding:NSUTF8StringEncoding]];
[Y_body appendData:[[NSString stringWithFormat:@"%@\r\n", [Y_params objectForKey:Y_param]] dataUsingEncoding:NSUTF8StringEncoding]];
}
//添加图片数据
NSData *Y_imageData = UIImageJPEGRepresentation(imageSearch, 0.1);
if (Y_imageData) {
[Y_body appendData:[[NSString stringWithFormat:@"--%@\r\n", Y_boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[Y_body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"image.jpeg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[Y_body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[Y_body appendData: Y_imageData];
[Y_body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
}
[Y_body appendData:[[NSString stringWithFormat:@"--%@--\r\n", Y_boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[Y_request setHTTPBody:Y_body];
[Y_request setURL:Y_requestURL];
[_myWebView loadRequest:Y_request];
此Yandex搜索查询。此查询仅适用于iPhone,但不适用于Ipad,为什么? 谢谢你的回答。