ı try to send string request but its not work
var request = URLRequest(url: url)
request.httpMethod = "POST"
let parameters = "{"Language": "tr","ProcessType": 1,"Username": "(self.mailTextField.text ?? "")","Password": "(self.passwordTextField.text ?? "")"}"
print(parameters)
let enUrlParams = try! parameters.aesEncrypt(key: LoginConstants.xApiKey, iv: LoginConstants.IV)
print(enUrlParams)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("*/*", forHTTPHeaderField: "Accept")
request.httpBody = enUrlParams.data(using: .utf8)
Output:
{"Language": "tr","ProcessType": 1,"Username": "","Password": ""}
l+Au1MhqAlHr+wDR9UmdjN4IL5XHVnwMJx3rHF/P1MT+aO5Q5YF25f5OJRwDVzXEWu47ocqMxcUqw1onYBya9VCEvqjNQ0FpNCxtPp9fh+Y=
Optional(108 bytes)
statusCode should be 200, but is 500
response = Optional(<NSHTTPURLResponse: 0x600000e36e00> { URL: "my url" } { Status Code: 500, Headers {
Date = (
"Wed, 14 Sep 2022 11:54:35 GMT"
);
Server = (
"Microsoft-IIS/10.0"
);
"Transfer-Encoding" = (
Identity
);
"X-Powered-By" = (
"ASP.NET"
);
} })
responseString = Optional("")
2
Answers
I solved problem let stringRequest = ""(enUrlParams)"" this part solved my problem
If you are getting 500 as HTTP Response Code, then you need to check with the API Team, as 500 is Server Not Available.
If, Status Code lies in 4xx, then you need to bother about code, For 5xx you Server /API is not responding to your request.