如何让Alamofire对该网址进行编码-它会不断删除参数 [英] How do I get Alamofire to Encode this Url - it keeps dropping parameter

查看:70
本文介绍了如何让Alamofire对该网址进行编码-它会不断删除参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让Alamofire使用URLEncoded对该URL进行如下编码


https://domain.com/rest/api/2/search?query= assignment = user123()%20order%20by%20lastUp%20desc


我使用了以下代码:

 让端点= https://domain.com/rest/api/2/search/ 
让参数:[ String:AnyObject] = [ query:, assignment: user123()由lastUpdated desc命令]

,但是当Alamofire对网址进行编码时,它会完全删除 query参数并给出以下信息:


https://domain.com/rest/api/ 2 / search?assignment = user123()%20order%20by%20lastUp%20desc //查询参数丢失


lockquote>


  1. 我尝试将参数更改为此:



    让端点= https://domain.com/rest/api/2/search/
    let params:[String:AnyObject] = [ query: assignment = user123()由lastUp desc命令]


但是它将 =符号编码为%20%3D%20



有人建议我如何使它工作吗?

解决方案

看起来是唯一的建议使它正常工作只是根本不使用任何参数,而是按原样放置整个端点。

  let EndpointFull = https://domain.com/rest/api/2/search?query=assignment=user123() %20order%20by%20lastUp%20desc 

Alamofire.request(.GET,endpointFull)

如果我们可以指定参数的顺序,那就更好了。


I am trying to get Alamofire to encode this url as below using URLEncoded

https://domain.com/rest/api/2/search?query=assignment=user123()%20order%20by%20lastUp%20desc

I have used the following code:

let endpoint = "https://domain.com/rest/api/2/search/"
 let params:[String:AnyObject] = ["query" : "","assignment" : "user123() order by lastUpdated desc"] 

but when Alamofire encodes the url it drops the "query" parameter altogether and gives me this:

https://domain.com/rest/api/2/search?assignment=user123()%20order%20by%20lastUp%20desc // query parameter missing

  1. I have tried changing the parameters to this:

    let endpoint = "https://domain.com/rest/api/2/search/" let params:[String:AnyObject] = ["query" : "assignment=user123() order by lastUp desc"]

however it encodes the "=" sign as %20%3D%20

Does anyone have a suggestion, how I can get this to work?

解决方案

Looks like the only way to get it to work was just to not use parameters at all and put the full endpoint as is.

let endpointFull = https://domain.com/rest/api/2/search?query=assignment=user123()%20order%20by%20lastUp%20desc  

 Alamofire.request(.GET, endpointFull)

Would have been much nicer if we could specify the order of the parameters.

这篇关于如何让Alamofire对该网址进行编码-它会不断删除参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆