我使用HTTP PUT方法將base64編碼的圖像字符串傳遞到服務器端。我嘗試了幾次,但得到錯誤消息作爲響應。該錯誤消息是因爲空值正在服務器端。我已經檢查了相同的,在android代碼和它的工作很好。我在下面附上我的代碼。圖像上傳中的問題 - base64編碼
SBJSON *parser = [[SBJSON alloc] init];
NSString *url=[NSString stringWithFormat:@"The URL i am using"] ;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"XXXXX" forHTTPHeaderField:@"USER_AGENT"];
[request setHTTPMethod:@"PUT"];
NSString *input=[NSString stringWithFormat:@"abc[image]=%@",base64encodedString];
[request setHTTPBody:[input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSASCIIStringEncoding];
NSDictionary *statuses = [parser objectWithString:json_string error:nil];
[parser release];
[json_string release];
return statuses;
我從服務器端收到如下錯誤消息:「xxxxxx.jpg不能被'identify'命令識別。
請提出解決方案。
最後我發現內容類型應該從「application/x-www-form-urlencoded」改爲「multipart/form-data」。任何人都可以告訴我如何通過基地編碼的字符串使用這種方式?請...在過去的20天裏,我在這個問題背後......
allowLossyConversion:數據是YES不是一個好主意。 嘗試轉儲您在服務器端收到的內容。 – ssteinberg
@ssteinberg:我已經添加了來自服務器端的錯誤消息..也感謝您的建議。 – Praveen