我希望发送一个非常长的String,这是一个编码成String的图像。我需要使用POST方法发送该信息。我在Android using key-value pair
中实现了相同的功能,我需要在iOS中使用键值对实现相同的功能。请帮助我提供有用的资源/方法。
编辑1
我尝试过什么
[dictionnary setObject:@"admin" forKey:@"username"];
[dictionnary setObject:@"123123" forKey:@"password"];
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionnary
options:kNilOptions
error:&error];
NSString *urlString = @"MY CALL URL";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonData];
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSLog(@"response is obtained");
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ;
NSLog(@"%@", responseString);
编辑2
我收到错误
Request Error Error Domain=kCFErrorDomainCFNetwork Code=303 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 303.)" UserInfo=0x7ba0120 {NSErrorFailingURLKey=http://yahoo.com/, NSErrorFailingURLStringKey=http://yahoo.com/}
答案 0 :(得分:0)
您可以使用NSMutableDictionary
答案 1 :(得分:0)
在帖子词典中添加图片字符串:
[dictionnary setObject:imageEncodedString forKey:@"image"];