在 PHP 中执行 HTTPResponse

发布于 2024-12-02 21:34:40 字数 1407 浏览 1 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涙—继续流 2024-12-09 21:34:40

默认情况下,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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文