简体   繁体   中英

Alamofire GET request parameters

When send GET request with parameters, url encoded in a different way

http://someurl/search-ads?attributes[elevator]=1&attributes[ranges][square][]=20.0&attributes[ranges][square][]=170.0&cities[]=somecity&currency=kgs&has_images=0&not_first_floor=1&not_last_floor=1&order_type=sale&rating__gte=5&rating__lte=10000&specialty=2

but it should be

http://someurl/search-ads?specialty=7&order_type=sale&attributes={"ranges":"{\"square\":[2450,8190]}"}&cities=somecity&page=1 

Is there any settings to change, to force Alamofire to encode in second way?

I am using Alamofire 3

Here is my method

func makeSearch(search: GeneralSearch) {
        let request = Alamofire.request(.GET, SearchURL, parameters: Mapper().toJSON(search), encoding: .URL).validate().responseJSON {
            response in
            switch response.result {
            case .Success:
                if let responseValue = response.result.value {
                    print(responseValue)
                }
                break
            case .Failure(let error):
                print("Error: " + error.localizedDescription)
                break
            }
        }
    }

In Swift 3 and Alamofire 4

This is the latest syntax for the get method

Alamofire.request(" Your URL Here ", method : .get, parameters: Parameter).responseJSON { response in
            let data = response.result.value as! NSArray
            for dfd in data
            {
                self.Arrayimages.append(dfd as! String)
                print(dfd)
                self.collectionView.reloadData()
            }
        }

Hope This may help as an Reference

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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