let params = "name=Thobio Joseph&googleid=24356567890uyy4546&[email protected]&avatar=https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAv0AAAAJDZjZGJjMTFjLWNiNzAtNGYzNy1iMDE4LTA2MzBmNzUwZGExNQ.jpg"
func postMethodUploadDataToServerLoginPage() {
Alamofire.request(loginUrl, method:.post,parameters:params.data(using: String.Encoding.utf8),encoding:URLEncoding.default).responseJSON { response in
switch response.result {
case .success:
print(response)
case .failure(let error):
failure(0,"Error")
}
}
-2
A
回答
0
首先你PARAMS是错误的,你需要传递一个字典[key:value]
,然后你需要将其转换成JSON,并把你的请求主体,也如果您正在使用Alamofire.request
你不”吨需要通过urlString,只有一个请求,这个代码尝试
func postMethodUploadDataToServerLoginPage() {
let paramToSend = ["name":"Thobio Joseph","googleid":"24356567890uyy4546","email":"[email protected]","avatar":"https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAv0AAAAJDZjZGJjMTFjLWNiNzAtNGYzNy1iMDE4LTA2MzBmNzUwZGExNQ.jpg"]
let request = NSMutableURLRequest(url: URL(string: loginUrl)!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try! JSONSerialization.data(withJSONObject: parameters)
Alamofire.request(request).responseJSON { (response) in
switch response.result {
case .success:
print(response)
case .failure(let error):
failure(0,"Error")
}
}
希望这有助于
+0
如果php post方法如$ _POST ['name'],$ _ post ['email']会不会需要json –
+0
@ThobioJoseph你试过我的答案?,必须工作,试试并让我知道 –
+0
yes我尝试我得到它非常感谢你:) –
相关问题
- 1. Alamofire - 额外参数'方法'在调用
- 2. Alamofire V4额外的参数方法
- 3. 调用中额外的参数“方法”。 Alamofire
- 4. Alamofire调用中的额外参数“方法” - 自定义ParameterEncoding
- 5. Swift Alamofire请求错误 - 在调用中额外的参数
- 6. ObjectDataSource不调用插入方法,当它有额外的参数
- 7. 呼叫中的额外参数“方法”
- 8. Swift方法 - 多个参数“调用中的额外参数”错误
- 9. Swift - 调用中额外的参数'count'?
- 10. 在调用中的额外参数
- 11. 调用CLLocation中的额外参数'userinfo'
- 12. 调用swift中的额外参数
- 13. Swift在调用中的额外参数
- 14. Alamofire要求得到错误'额外的参数在呼叫'
- 15. 使用额外参数重写django model.py的删除方法
- 16. 额外拼抢(链接)方法调用到__get()魔法方法
- 17. Alamofire:无法调用“的URLRequest”类型的参数列表“(方法,NSURL)”
- 18. Alamofire 4.4.0:在呼叫额外的参数为“方法”:不知道什么是投掷的错误
- 19. ViewController中的函数“调用中的额外参数”
- 20. startLogging(Twisted)的额外参数?
- 21. 额外的参数呼叫
- 22. 奇怪的额外参数
- 23. bsddb.open额外的参数
- 24. 带socket.io的额外参数
- 25. 调用自定义函数的额外参数?
- 26. forEach中调用函数的额外参数
- 27. 意图额外的方法?
- 28. 使用swift时在调用时额外的参数为绿色
- 29. 调用一些方法用于额外的计算
- 30. 用R的额外参数减少R
你能解释一下你正在尝试做的,这个问题你可能会面对的? – Nisarg