如何将此cURL命令转换为目标c

时间:2016-05-12 19:21:24

标签: ios objective-c curl

我正在尝试将此cURL命令转换为objective-c,但无法找到有关objective-c库的“-i”和“-u”的任何信息。

curl -i -u "username" "https:domain.com/v1/authenticate"

2 个答案:

答案 0 :(得分:0)

Google "man curl",比创建SO问题更容易。

  

-i
                (HTTP)在输出中包含HTTP标头。 HTTP标头                 包括服务器名称,文档日期,HTTP-                 版本等......

     

-u
                指定用于服务器身份验证的用户名和密码 -                 灰。

答案 1 :(得分:0)

curl -X GET 
--header "Accept: application/json" 
--header "app_id: 999999" 
--header "app_key: xxxxxxx" 
--header "Dev-Mode: true" "https://api.infermedica.com/v2/symptoms"

Objective-C代码

(void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    //CURL

    //curl -X GET --header "Accept: application/json" --header "app_id: 795edb00" --header "app_key: c68cb95e54ec04f44544bb5fd7ab5125" --header "ev-Mode: true" "https://api.infermedica.com/v2/symptoms"


    NSString *str = [NSString stringWithFormat:@"https://api.infermedica.com/v2/symptoms;app_id=795edb00;app_key=c68cb95e54ec04f44544bb5fd7ab5125"];

    NSURL *url = [[NSURL alloc]initWithString:str];
    NSData *data = [[NSData alloc ]initWithContentsOfURL:url];

    arr = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

    NSLog(@"%@",arr);