Ios 当档案更新在swift中使用Alamofire时出错?

Ios 当档案更新在swift中使用Alamofire时出错?,ios,json,swift,alamofire,Ios,Json,Swift,Alamofire,我正在使用Alamofire通过.GET方法更新配置文件。如果我在任何字段的字符之间使用任何空格,则其错误为致命错误:在展开可选值时意外发现nil。但是如果我在Postman上测试相同的URL,则会成功更新。所以,通过应用程序了解为什么它会在Alamofire中产生错误 @IBAction func btnSavePressed(sender: AnyObject) { Firstname = txtFName.text! Lastname = txtLname.text!

我正在使用Alamofire通过.GET方法更新配置文件。如果我在任何字段的字符之间使用任何空格,则其错误为
致命错误:在展开可选值时意外发现nil
。但是如果我在Postman上测试相同的URL,则会成功更新。所以,通过应用程序了解为什么它会在Alamofire中产生错误

 @IBAction func btnSavePressed(sender: AnyObject) {

    Firstname = txtFName.text!
    Lastname = txtLname.text!
    Username = txtUname.text!
    Phone = Int(txtPhone.text!)
    DoorNo = txtDoorNo.text!
    Street = txtStreet.text!
    Town = txtTown.text!
    Postcode = Int(txtPostCode.text!)

    print(Firstname)
    print(Lastname)
    print(Username)
    print(Phone)
    print(DoorNo)
    print(Street)
    print(Town)
    print(Postcode)
    print("http://\(platform).eposapi.co.uk/?app_id=\(apiID)&app_key=\(apikey)&request=\(request)&id=\(UserID)&fname=\(Firstname)&lname=\(Lastname)&phone=\(Phone)&dno=\(DoorNo)&add1=\(Street)&add2=\(Town)&postcode=\(Postcode)")

    UPDATE_data_from_URl()
}

 func UPDATE_data_from_URl(){

    Alamofire.request(.GET, "http://\(platform).eposapi.co.uk/?app_id=\(apiID)&app_key=\(apikey)&request=\(request)&id=\(UserID)&fname=\(Firstname)&lname=\(Lastname)&phone=\(Phone)&dno=\(DoorNo)&add1=\(Street)&add2=\(Town)&postcode=\(Postcode)", parameters: nil )
        .responseJSON {
            response in
            print(response)

            if let result: AnyObject = response.result.value {

                let post: JSON = JSON(result)

                let action = post["action"].boolValue
                let info = post["info"].stringValue
                print(action)
                print(info)

                if action == false{
                    let alert = UIAlertController(title: "", message: info, preferredStyle: UIAlertControllerStyle.Alert)
                    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
                    self.presentViewController(alert, animated: true, completion: nil)
                }
                else{
                    let alert = UIAlertController(title: "Success", message: info, preferredStyle: UIAlertControllerStyle.Alert)

                    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default){
                        (action) in



                        let sb = UIStoryboard(name: "Main", bundle: nil)
                        let vc = sb.instantiateViewControllerWithIdentifier("yourtabbarvcidentifier") as! UITabBarController
                        vc.selectedIndex = 0
                        self.revealViewController().pushFrontViewController(vc, animated: true)


                        })
                    self.presentViewController(alert, animated: true, completion: nil)

需要删除字符串中的空白,然后重试

let linkString = "http://maps.google.com/maps?q=\(Location!)"
let address = NSURL(string:linkString.stringByReplacingOccurrencesOfString(" ", withString: ""))!

使用另一个API,
Alamofire.request(.GET,baseUrl,参数:yourParamsHere,编码:.urlcoded,头:nil)
这将使url等在使用空格时也能正常工作,但没有POST方法。因此,在参数中,我应该使用什么here@Shubhanki已经向您展示了问题中仅有的GET方法检查您的有效值是否为空,同时使用GET如何传递参数。。我在POSTmethod中只有pass参数。给我一些想法@Shubhank