현재 HTTP POST를 통해 서버에 이미지를 업로드하고 있습니다. 아래 코드를 사용하면 모든 것이 잘 작동합니다.Imageshack에 대한 HTTP POST
NSString *UDID = md5([UIDevice currentDevice].uniqueIdentifier);
NSString *filename = [NSString stringWithFormat:@"%@-%@", UDID, [NSDate date]];
NSString *urlString = @"http://taptation.com/stationary_data/index.php";
request= [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[NSData dataWithData:imageData]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(returnString);
그러나 Image Shacks XML API를 사용하도록 변환하려고하면 아무 것도 반환하지 않습니다. ImageShack의 지시 사항은 다음과 같습니다.
POST를 통해 다음 변수를 imageshack으로 보냅니다. us /index.php
fileupload; (이미지) xml = "예"; (XML 반환 지정) 쿠키; (등록 코드, 선택 사항)
내가 여기에서 어디로 가야하는지 아는 사람이 있습니까?