error: inputDataNilOrZeroLength in Swift with Alamofire
For me was right:
let authRequest = AF.request(url,
method: .post,
parameters: parameters,
encoding: JSONEncoding.default)
authRequest.responseString { response in
switch response.result {
case .success(let value):
print("succes")
case .failure(let error):
print("Error while querying database: \(String(describing: error))")
}
}
JSONEncoding + responseString(Just for more convenience)
responseSerializationFailed with Alamofire
Try this
Paramters:
let parameters: [String: Any] = [
"jsonrpc":"2.0",
"method":"call",
"params": [
"db": db,
"login": "mohanad@amana.ps",
"password": "mohanad123",
]
]
request. use a encoding: JSONEncoding.default
, because you have pass Raw value.
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil)
.validate(statusCode: 200..<600)
.responseJSON { response in
switch response.result
{
case .failure(let error):
if let data = response.data {
print("Print Server Error: " + String(data: data, encoding: String.Encoding.utf8)!)
}
print(error)
case .success(let value):
print(value)
}
}
your api give me this type of data in this
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>400 Bad Request</title>\n<h1>Bad Request</h1>\n<p>Session expired (invalid CSRF token)</p>\n"
Alamofire responseSerializationFailed
I managed to fix the issue after a couple of days of searching and debugging. When entering the URL for the Alamofire request I was using the URL formatted like https:///www.test.com
. I added an extra slash at the end as follows https:///www.test.com/
According to what I found, the request will get redirected to the correct URL and the headers are not sent along with the request. Thus explaining the 401 response (Unauthorized)
Related Topics
Firebase Cloud Messaging - Check Existing or Available Topics
How to Prevent Duplicate Entry on Parse
Change iPhone Uislider Bar Image
Nstimer Timerwithtimeinterval: Not Working
Where to Store Global Constants in an iOS Application
Auto Layout in Uicollectionviewcell Not Working
Setting Selected Image in Tab Bar Controller with Storyboard
How to Find Bluetooth Audio Devices in iOS
What Is the Second Parameter of Nslocalizedstring()
How to Add Multiple Collection Views in a Uiviewcontroller in Swift
Swift: Can't Get Nsdate Dateformatter Right
iPhone Gps in Background Never Resumes After Pause
How to Remove Provisioning Profiles from Xcode
Perform Segue Programmatically and Pass Parameters to the Destination View
Remove Separatorinset on iOS 8 Uitableview for Xcode 6 iPhone Simulator