when i give same parameters i am getting response in postman like this
code: why i am not getting response like postman in this makeMultipartRequest() call? where am i wrong? how to get response and error while parsing.
func makeMultipartRequest() {
let url = "https://test.com/SaveUndertakingAckowledgement"
let parameters: [String: Any] = [
"SchCode": "Test",
"key": "ndjsfnjkds==",
"UserID": 11,
"UserType": 3,
"UtID": "kfnksdlnfks"
]
Alamofire.upload(multipartFormData: { multipartFormData in
for (key, value) in parameters {
if let data = "\(value)".data(using: .utf8) {
multipartFormData.append(data, withName: key)
}
}
}, to: url) { result in
switch result {
case .success(let upload, _, _):
upload.responseJSON { response in
switch response.result {
case .success(let value):
print("Response JSON: \(value)")
// Handle success response
case .failure(let error):
print("Error: \(error)")
// Handle error
}
}
case .failure(let error):
print("Error: \(error)")
// Handle error
}
}
}
func makePostRequest() {
let url = "https://test.com/SaveUndertakingAckowledgement"
let parameters: [String: Any] = [
"SchCode": "test",
"key": "nsjdkfn--=",
"UserID": 11,
"UserType": 3,
"UtID": "ewiw/D264"
]
Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: nil)
.responseJSON { response in
switch response.result {
case .success(let value):
print("Response JSON only post...: \(value)")
// Handle success response
case .failure(let error):
print("Error only post...: \(error)")
// Handle error
}
}
}
Response JSON:
{
Message = "No HTTP resource was found that matches the request URI 'https://gfvhv.test.com/SaveUndertakingAckowledgement'.";
MessageDetail = "No action was found on the controller 'User' that matches the request.";
}

Regarding your Postman screen, you need do a "simple" POST (no multiform part) and put the parameters in the URL (while for a POST it's usually in the
httpBody).The Alamofire solution would be then:
With
URLEncoding(destination: .queryString)you should be able to tell to put the parameters inside the URL (ie as the query).Side note: You can generate
cURLwith POSTMAN, and you can generatecURLwith Alamofire. It's can be really helpful to have a common ground for comparison and trying to match the working solution.In Alamofire, you just need:
In your case, I got:
Except for the User-Agents, Accept-Language, Accept-Encoding which are more specific to the app/device and are usually not problematic, we see that the parameters have been added to the URL.