How I can make a HTTPResponse in php? I'm having some trouble :( I should read the response from a cocoa application. This is my php code:
<?php
HttpResponse::setCache(true);
HttpResponse::setContentType('text/plain');
HttpResponse::setData("Some data");
HttpResponse::send();
?>
Then here is my Cocoa Code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
NSURL *url = [NSURL URLWithString:@"Web site"];
NSURLRequest *theRequest开发者_Go百科=[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);
}
But it doesn't work :( Ideas?
The http library is not included with PHP by default as detailed on this page of the manual http://www.php.net/manual/en/http.install.php, so you probably need to install it on your system.
The 'not found' error suggests that you haven't installed it yet, so you need to follow the steps in the instructions.
Also see here for more information http://php.net/http
精彩评论