Restangular post data作为有效负载而不是查询字符串

时间:2016-08-27 23:30:26

标签: javascript angularjs ajax xmlhttprequest restangular

现在我有了我的后端服务,可以通过以下网址向我们的系统注册新用户:

 let DeviceInfo = [
                    "ImageUrl":profileImageUrl!,
                    "DeviceName":self.DeviceName.text!,
                    "Description":self.Description.text!,
                    "Category":self.itemSelected
                    ]

    self.ref.child("Devices").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEventOfType(.Value, withBlock: {(snapShot) in

        if snapShot.exists(){

            let numberOfDevicesAlreadyInTheDB = snapShot.childrenCount

            if numberOfDevicesAlreadyInTheDB < 5{

                let newDevice = String("Device\(numberOfDevicesAlreadyInTheDB+1)")

                let userDeviceRef = self.ref.child("Devices").child(FIRAuth.auth()!.currentUser!.uid)

                userDeviceRef.observeSingleEventOfType(.Value, withBlock: {(userDevices) in

                    if let userDeviceDict = userDevices.value as? NSMutableDictionary{

                        userDeviceDict.setObject(DeviceInfo,forKey: newDevice)

                        userDeviceRef.setValue(userDeviceDict)
                    }
                })
             }
                else{
                    //Show Alert that user cant enter Devices Anymore
                }
            }else{
              self.ref.child("Devices").child(FIRAuth.auth()!.currentUser!.uid).setValue(["Device1" : DeviceInfo])
            }
        }) 

使用Restangular总是会导致帖子请求以查询字符串

的形式发送
/api/users/register

标题

Restangular.all('users').post("register",registerData)

这里的问题,如何将注册表单参数作为有效负载发布?

有效载荷: payload

查询字符串: enter image description here

页眉: headers

1 个答案:

答案 0 :(得分:0)

尝试将数据作为第一个参数发送:

Restangular.all('users').one("register").customPOST({name:"xyz"}, '', {}, {});

https://github.com/mgonto/restangular/blob/master/README.md处的文档似乎已经完整。很高兴看到!