【问题标题】:How would I represent this CURL using ASIHTTPRequest?我将如何使用 ASIHTTPRequest 表示这个 CURL?
【发布时间】:2011-08-25 20:51:50
【问题描述】:
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];

当我使用上面的代码时,我收到“需要授权”的响应,所以我一定是做错了什么。

【问题讨论】:

    标签: iphone curl asihttprequest urbanairship.com


    【解决方案1】:

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

    您可以通过调用::

    使其在服务器不询问的情况下发送它们
    [request setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic];
    

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 2017-07-10
      • 2021-05-17
      • 2015-10-21
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      相关资源
      最近更新 更多