나는이 PHP 스크립트로 데이터를 보내려고 :누구든지이 POST NSMutableURLRequest에서 PHP 스크립트에 오류를 찾을 수 있습니까?
mb_internal_encoding("UTF-8");
if(isset($_POST['format']) && isset($_POST['category']) && isset($_POST['title']) && isset($_POST['description']) && isset($_FILES['photo']) {
save($_POST['category'], $_POST['title'], $_POST['description'], $_FILES['photo']);
} else {
echo "There was an error, a field does not exist, please try again!<br />";
echo "format = " . $_POST['format'] . "<br />";
echo "category = " . $_POST['category'] . "<br />";
echo "title = " . $_POST['title'] . "<br />";
echo "description = " . $_POST['description'] . "<br />";
echo "photo =" . $_FILES['photo'] . ;
}
...
...
그리고 아이폰에서이 Objc 코드와 syncronousRequest를 보내려고 해요 :
//creating the url request:
NSURL *cgiUrl = [NSURL URLWithString:@"http://www.hhh.com/uploading.php"];
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:cgiUrl];
//adding header information:
[postRequest setHTTPMethod:@"POST"];
NSString *stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
[postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
//setting up the body:
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"category\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"iPhone"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"format\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"jpg"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:self.theTitle] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"description\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:self.theCaption] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"photo\"; filename=\"%@.jpg\"\r\n", self.theTitle] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[NSData dataWithData:UIImageJPEGRepresentation(resizedImage(self.myPhoto, CGRectMake(0, 0, 600, 800)), 0.5)]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postRequest setHTTPBody:postBody];
NSError *theError;
NSData *returnData = [ NSURLConnection sendSynchronousRequest: postRequest returningResponse: nil error:&theError ];
NSString *returnDataString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"[DEBUG]... response from request: %@", returnDataString);
그러나 대답은 :
[DEBUG] ... 요청에서 응답 : 오류가 발생하여 모든 필드에 이 존재하지 않습니다. 다시 시도하십시오!
형식 내가 잘못 뭐하는 거지 =
카테고리 =
제목 =
설명 =
사진 = 위도 =
경도 =
? 왜냐하면 내가 보는 것은 밭이 없다는 것입니다.
예, 다른 스크립트를 사용하고 있으며 한 번에 하나의 값만 보내면 파일을 보내면 실패한 부분이 발생합니다 ... 계속하겠습니다. 감사합니다. – Carlos