ios - 如何使用 curl 登录服务器?

标签 ios objective-c json curl afnetworking

我想与服务器通信。

服务器需要以下信息:

{
  "user": {
    "email": "user@example.com",
    "password": "secret",
    "password_confirmation": "secret",
    "seed_recipes": true          //not obligatory files
  }
}

这里是 curl :

curl -d "user[email]=user@example.com" -d "user[password]=password" -d "user[password_confirmation]=password" -d "user[seed_recipes]=true" http://domain.com/users

我在下面写了以下内容,服务器显示这些错误

(
email =     (
        "can't be blank",
        "is invalid"
    );
    password =     (
        "can't be blank"
    );

这是我的代码:

NSDictionary *parameters = @{@"user[email]":email, @"user[password]":password, @"user[password_confirmation]":password_confirmation};

    [manager POST:@"http://domain.com/users" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

看来我可能没有向服务器发送正确的消息。 有谁知道如何纠正 curl ?

最佳答案

NSDictionary *parameters = @{@"user": @{@"email": email, @"password": password, @"password_confirmation": password_confirmation}};

关于ios - 如何使用 curl 登录服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31025488/

相关文章:

ios - UITabBarController 中的 UISplitViewController 在尝试检查 [splitViewController viewControllers] 时出错

Java通过迭代实现多个HttpURLConnections?

java - 尝试序列化具有惰性获取类型的实体

ios - 尝试绘制图表时应用程序崩溃

ios - 在 UICollectionView 中,我如何预加载 cellForItemAtIndexPath 之外的数据以在其中使用?

ios - 将文件字符串名称从文档目录加载到数组中

iphone - 如何检查 UITextField 的文本是否是有效的电子邮件?

ios - 转换为 Swift 3/Xcode 8 后的 Storyboard 预览问题

iphone - iOS 应用程序被拒绝 - 数据存储指南

java - Android,解析 JSON 对象