【问题标题】:how to make cURL call in Objective C?如何在 Objective C 中进行 cURL 调用?
【发布时间】:2012-04-27 22:32:08
【问题描述】:

请任何人帮助对以下网址进行 cURL 调用

curl -u "demo:demo" -H "Accept: application/json" http://api.holdsport.dk/v1/teams

这对我继续我的项目真的很有帮助。 demo:demo是用户名和密码

谢谢。

【问题讨论】:

  • 查看NSTask,最好查看NSURLConnectionAFNetworking

标签: iphone objective-c nsurlrequest


【解决方案1】:

cURL 所基于的libcurl 项目是基于C 的,并且由于C 是Objective-C 的子集(许多示例here),因此可以完美运行。虽然如果您只针对 Cocoa/Cocoa Touch,那么 NSURLConnection 类(或更高级别的 ASIHTTPRequest 或 AFNetworking 第三方库)会更容易(开箱即用的异步处理)。

编辑:其实如果你真的想使用 cURL,有Cocoa bindings for it

【讨论】:

    【解决方案2】:

    这就是我看到的 http 请求的方式

    //Create a new url request with our url path
    myRequest_ = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:URL_PATH]];
    myRequest_.delegate = self;
    
    //send out the request as asynchronous
    [myRequest_ startAsynchronous];
    

    http://www.roostersoftstudios.com/2011/10/16/iphone-dev-how-to-communicate-with-server-using-http-json-and-phpor-any-server-side-language/

    【讨论】:

    • 需要注意的是ASIHTTPRequest很棒,但是不标准。这是一个可以集成到应用中的库。
    • 我建议人们在使用非标准扩展之前学习如何使用标准库。在许多情况下,人们使用 ASIHTTPRequest 只是因为他们现在没有具有相同功能的标准库。
    猜你喜欢
    • 2011-12-17
    • 2010-11-04
    • 2014-10-10
    • 2019-09-27
    • 2016-11-18
    • 1970-01-01
    • 2016-12-19
    • 2011-11-06
    • 2014-10-24
    相关资源
    最近更新 更多