【发布时间】:2018-07-18 22:56:33
【问题描述】:
Alamofire 返回一个无效的 URL
我正在使用以下代码形成一个用于搜索的 URL 字符串 (urlStrForCustSearch)
和URL_CUSTOMER_SEARCH = "http://pos1domain.mobi/pos/SV_IOS.asmx/IosJasonToDatatbl":
let customerJson = [[
"customer_id":nil,
"tel":1234567,
"email":nil,
"addr":nil,
"history":nil]]
do{
let JSONData = try JSONSerialization.data(withJSONObject: customerJson, options: [])
let JSONText = String(data: JSONData,
encoding: .utf8)!
let urlStrForCustSearch = URL_CUSTOMER_SEARCH+"?jsonText=\(JSONText)&funname=GET_MM_CUSTOMER_DTL_LST"
print(urlStrForCustSearch)
Alamofire.request(urlStrForCustSearch, method: .post, parameters: [:], encoding: URLEncoding.default, headers: [:]).responseString { response in
if response.result.isSuccess {
print("Response is success")
}else{
print("Response Failed")
print("Reason : \(response)")
}
}
}catch{
print("Cannot parse the dictionary")
}
控制台打印所需的网址
正确的网址:
http://pos1domain.mobi/pos/SV_IOS.asmx/IosJasonToDatatbl?jsonText=[{"tel":1234567,"email":null,"history":null,"customer_id":null,"addr":null}]&funname=GET_MM_CUSTOMER_DTL_LST
但是在将urlStrForCustSearch 字符串作为参数传递给 Alamofire 时,Alamofire 返回无效 URL
响应失败
原因:FAILURE: invalidURL("http://pos1domain.mobi/pos/SV_IOS.asmx/IosJasonToDatatbl?jsonText=[{\"tel\":1234567,\"email\":null,\"history\":null,\"customer_id\":null,\"addr\":null }]&funname=GET_MM_CUSTOMER_DTL_LST")
我们可以看到 '\' 被添加到 url 字符串中
谁能帮我创建没有'\'字符串的url字符串
如果需要任何输入,请告诉我。
【问题讨论】:
标签: json swift string url alamofire