【问题标题】:Postman giving different response邮递员给出不同的回应
【发布时间】:2018-07-04 13:40:09
【问题描述】:
我是 swift iOS 的初学者,我正在 iOS 中做一个应用程序的登录模块,但我被困在一件事上,我有登录 api,但是当我在邮递员中检查响应时,我将参数发送为“原始”而不是它显示用户已登录,但是当我发送与“表单数据”相同的参数时,它显示错误的 ID 和密码......谁能告诉我如何将参数作为“原始”发送,以便我可以正确回复??谢谢你的帮助!!
【问题讨论】:
标签:
ios
swift
post
postman
【解决方案1】:
如果您使用 Alamofire 库进行 API 调用,请尝试此方法。
func request(_ method: HTTPMethod
, _ URLString: String
, parameters: [String : AnyObject]? = [:]
, headers: [String : String]? = [:]
, onView: UIView?, vc: UIViewController, completion:@escaping (Any?) -> Void
, failure: @escaping (Error?) -> Void) {
Alamofire.request(URLString, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.responseJSON { response in
switch response.result {
case .success:
completion(response.result.value!)
case .failure(let error):
failure(error)
}
}
}
另外请记住,在调用此方法时您需要传递 Application/JSON 标头。
["Content-Type": "application/json"]