我如何使用 ASIHTTPRequest 表示此 CURL?

发布于 2024-12-01 08:40:09 字数 816 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路弥 2024-12-08 08:40:09

默认情况下,ASIHTTPRequest 仅在服务器请求后才发送用户名/密码。

您可以通过调用以下命令使其发送它们而无需服务器询问:

[request setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文