How would I represent this CURL using ASIHTTPRequest?
curl -X POST -u "<application key>:<master secret>" \
-H "Content-Type: application/json" \
--data '{"device_tokens": [开发者_运维知识库"<token>"], "aps": {"alert": "Hello!"}}' \
https://go.urbanairship.com/api/push/
I didn't understand how to add the application key and master secret into the header. This is the code that I have so far if this sparks any solutions.
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"https://go.urbanairship.com/api/push/"]] autorelease];
[request setRequestMethod:@"POST"];
request.username = @"APPLICATION KEY";
request.password = @"MASTER SECRET";
[request setPostValue:@"MY DEVICE CODE TOKEN" forKey:@"device_tokens"];
[request setPostValue:@"hello" forKey:@"alert"];
[request setDelegate:self];
[request startSynchronous];
When I use the code above I receive a response of "Authorization Required" so I must be doing something wrong.
By default, ASIHTTPRequest will only send the username/password once the server has requested them.
You can make it send them without the server asking by calling::
[request setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic];
精彩评论