2011-11-24 2 views
0

서버에서 데이터를 가져 오는 데 문제가 있습니다. 서버가 내 로컬 호스트입니다. 로컬 호스트에서버 objective-c에서 데이터 가져 오기

SMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"localhost"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0]; 

[request setHTTPMethod:@"GET"]; 
[request setHTTPBody:[NSString stringWithFormat:@"test.php"]]; 

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
if (connection) 
{ 
    NSLog(@"NSURLConnection connection==true"); 
    NSURLResponse *response; 
    NSError *err; 
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; 
    NSLog(@"responseData: %@", responseData); 
} 
else 
{ 
    NSLog(@"NSURLConnection connection==false"); 
}; 

나는 간단한 PHP 스크립트라는 test.php이 : 나는 사파리에서 로컬 호스트/test.php를 열고있어 경우

<?php 
echo "It works!!!" 
?> 

내가 볼 수있는 "그것은 작동을!"

+0

무엇이 문제입니까? –

+0

있는 NSURLConnection 연결 == 진정한 드 responseData : (널) – Oleg

답변

2

@ "localhost"대신 "http : // localhost"를 사용하십시오.

+0

그래! 감사. 지금 내 응답 데이터는 <3c3f7068입니다. 700a6563 686f2022 69742077 6f726b73 21212122 3b0a3f3e> – Oleg

+0

어떻게 인코딩 할 수 있습니까? – Oleg

+0

일반적으로 NSString * – Oleg