在 PHP 中执行 HTTPResponse
如何在 php 中创建 HTTPResponse?我遇到了一些麻烦 :( 我应该读取可可应用程序的响应。这是我的 php 代码:
<?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);
}
但它不起作用 :( 有想法吗?
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=[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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,PHP 中不包含 http 库,详细信息请参见本手册 http ://www.php.net/manual/en/http.install.php,因此您可能需要在系统上安装它。
“未找到”错误表明您尚未安装它,因此您需要按照说明中的步骤进行操作。
另请参阅此处了解更多信息 http://php.net/http
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