NSURLRequest HTTP POST에 문제가있어 어떤 문제가 있는지 알 수 없습니다.
NSString *urlString = @"http://localhost:8888/postpage";
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[url release];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSString *postString = @"sometext=Hello&language=en";
NSString *msgLength = [NSString stringWithFormat:@"%d", [postString length]];
[urlRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSString *returnString = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
NSLog의 결과이다 :
<html>
<head>
</head>
<body>
NOT SET
</body>
</html>
이 데이터를 작성하는 제 목표 C 코드
<html>
<head>
</head>
<body>
<?php
if (! isset($_POST['sometext'])) {
echo "NOT SET";
} else {
echo $_POST['sometext'];
}
?>
</body></html>
이다
:이
내 서버 측 PHP이고 이미 감사드립니다.
전에 라인을 이동하십시오 콘텐츠 길이 및 콘텐츠 유형을 추가 하시겠습니까? 서버가 해당 필드를 확인합니까? 답장을 기반으로 답변을 추가 할 수 있습니다. –
내 편집을 참조하십시오. 하지만 여전히 작동하지 않습니다. –
사용중인 인코딩 스타일에 대해 확실합니까? 또한 urlRequest가 아니고 요청하지 않아야합니까? 또한 http body를 설정하기 전에 추가해야합니다. 실제로 실행중인 코드를 게시 할 수 있습니까? –