2011-09-04 69 views
1

如何在PHP中創建一個HTTPResponse?我有一些麻煩:(我應該閱讀從一個可可應用程序的響應這是我的PHP代碼:在PHP中做一個HTTPResponse

<?php 
HttpResponse::setCache(true); 
HttpResponse::setContentType('text/plain');  
HttpResponse::setData("Some data"); 
HttpResponse::send(); 
?> 

那麼這裏就是我的可可代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self.view setBackgroundColor:[UIColor whiteColor]]; 
    NSURL *url = [NSURL URLWithString:@"Web site"]; 
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:url 
               cachePolicy:NSURLRequestUseProtocolCachePolicy 
              timeoutInterval:60.0]; 
     // create the connection with the request 
     // and start loading the data 
    NSURLConnection *theConnection=[[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease]; 
    if (theConnection) { 
     receivedData = [[[NSMutableData data] retain] autorelease]; 
     NSLog(@"OK!"); 
    } else { 
     NSLog(@":((("); 
    } 

} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
     // Append the new data to receivedData. 
     // receivedData is an instance variable declared elsewhere. 
    NSLog(@"DATA"); 
    NSString* aStr; 
    aStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; 
    NSLog(@"%@",aStr); 
} 

但事實並非如此工作:(想法?

+0

「它不工作」並沒有給我們太多的去不是嗎?你收到錯誤消息嗎?如果是這樣,請編輯您的問題以顯示它們。 http://www.php.net/manual/en/class.httpresponse.php – vascowhite

+0

它告訴我這一點:致命的錯誤:類'HttpResponse'找不到/membri/istopped/asd.php第2行 –

+0

你有沒有確定你的系統有HttpRequest? http://www.php.net/manual/en/http.requirements.php – vascowhite

回答