php - 在 PHP 中执行 HTTPResponse

标签 php cocoa httpresponse

如何在 php 中创建 HTTPResponse?我遇到了一些麻烦 :( 我应该读取 cocoa 应用程序的响应。这是我的 php 代码:

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

然后这是我的 cocoa 代码:

- (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);
}

但它不起作用:(想法?

最佳答案

默认情况下,PHP 中不包含 http 库,详细信息请参见本手册 http://www.php.net/manual/en/http.install.php ,因此您可能需要将其安装在您的系统上。

“未找到”错误表明您尚未安装它,因此您需要按照说明中的步骤操作。

另请参阅此处了解更多信息 http://php.net/http

关于php - 在 PHP 中执行 HTTPResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7299757/

相关文章:

objective-c - 如何从 Objective-C 或终端创建文件夹的 .dmg?

c# - 如何获取下载文件的完整路径

php - BjyAuthorize 对象管理器

PHP:将字符串转换为多维数组

php - 如何在 PHPUnit 中测试 cmp()

angularjs - 如何下载一个zip文件

php - 如何使用 CakePHP 3.4 输出自定义 HTTP 正文内容?回显导致 "Unable to emit headers"错误

php - 如何使用键从数组中删除元素

macos - cocoa 全局监视修改键按下

objective-c - Aaron Hillegass Cocoa Programming for Mac OS X 第 9 章问题