简体   繁体   English

将curl请求转换为AFNetworking 2.0

[英]Convert curl request to AFNetworking 2.0

I am working with the Balanced Payments API and in their example code they make a curl request as such: 我正在使用Balanced Payments API,在他们的示例代码中,他们提出了一个curl请求:

curl https://api.balancedpayments.com/v1/customers \
     -u ak-test-PE0kAimMqYDGzebPIHUzYwuLUM86yCxP: \
     -X POST

I am not sure how to pass the -u value in the AFNetworking 2.0 library. 我不知道如何在AFNetworking 2.0库中传递-u值。

Reference: Balanced Payments API 参考: Balanced Payments API

To authenticate with Balanced, you will need the API key secret provided from the dashboard. 要使用Balanced进行身份验证,您需要从仪表板提供API密钥。 You have to use http basic access authentication. 您必须使用http基本访问身份验证。 Your key has to be set as the username. 您的密钥必须设置为用户名。 A password is not required for simplicity. 为简单起见,不需要密码。

AFHTTPRequestOperation *operation = // …
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"ak-test-PE0kAimMqYDGzebPIHUzYwuLUM86yCxP:" password:@"unused" persistence:NSURLCredentialPersistenceForSession];
[operation setCredential:credential];

Persistence options are listed here . 此处列出了持久性选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM