我正在尋找發送很長的字符串,這是一個編碼爲字符串的圖像。我需要使用POST方法發送這些信息。我在Android using key-value pair
中實現了相同的功能,我需要在iOS中使用鍵值對實現相同的功能。請幫助我獲得有用的資源/方法。在iOS中對於長字符串的http-post請求
編輯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);
EDIT 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/}
http://whathaveyoutried.com/ – iDev
問題已更新。請看看 – onkar