json - How do I convert this curl command to Objective-C? -
i want data backend. should set request header authorization , use generate auth_token previous interaction backend. here curl
curl -h 'authorization: token token="replace-with-token"' http://domain.com/books
here code
nsurl *url = [nsurl urlwithstring:@"http://domain.com/books"]; config = [nsurlsessionconfiguration defaultsessionconfiguration]; [config sethttpadditionalheaders:@{@"token":@"4959a0bc00a15e335fb6"}]; nsurlsession *session = [nsurlsession sessionwithconfiguration:config]; [[session datataskwithurl:url completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) { nslog(@"%@", [nsjsonserialization jsonobjectwithdata:data options:0 error:nil]); }] resume];
i not sure if implemented curl correctly. data,which received backend, null . 1 know reason?
a curl header of 'authorization: token token="replace-with-token"' translate into:
[config sethttpadditionalheaders:@{@"authorization":@"token=\"4959a0bc00a15e335fb6\""}];
Comments
Post a Comment