我如何使用 ASIHTTPRequest 表示此 CURL?
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/
我不明白如何将应用程序密钥和主密钥添加到标头中。这是我到目前为止所拥有的代码,如果这能引发任何解决方案。
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];
当我使用上面的代码时,我收到“需要授权”的响应,所以我一定做错了什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,ASIHTTPRequest 仅在服务器请求后才发送用户名/密码。
您可以通过调用以下命令使其发送它们而无需服务器询问:
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::