Hi,
I'm getting strange behaviour when posting to get response from server which requires Basic Authorization.my token gets gets expired after every two hours.Every things works fine but some times i dn't knw but getting reponse from server "Parameter not null" error.i debuged there is nothing going null.i go through document-https://developer.apple.com/reference/foundation/nsmutableurlrequest
where mentioned some http headers could not be modified using methods
addValue(_:forHTTPHeaderField:)
or setValue(_:forHTTPHeaderField:)
i cannot figure where is going wrong and more when i'm setting Content & Accept type for json
addValue(_:forHTTPHeaderField:) workds gud to set authorization and for xml setValue(_:forHTTPHeaderField:) works but still .sometimes they breaks.Below is my code
//for json rsponse
func callWebserviceForJSON(_ urlStr: String ,callback:@escaping (_ data: Dictionary<String,String>) -> Void)
{
let url1 = URL(string: urlStr)
var request = URLRequest(url: url1!)
let tokenId = fileMgr.getCacheData(constants.defaultsKeys.TOKEN_KEY) as! String
let authorizationKey = "Basic ".appending(tokenId)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.addValue(authorizationKey, forHTTPHeaderField: "Authorization")
request.timeoutInterval = 20000.0
var dict = Dictionary<String,String>()
let task = URLSession.shared.dataTask(with: request)
{
data, response, error -> Void in
}
//for xml response
/
func callPostWebservice(_ urlStr: String, callback:@escaping (_ data: Dictionary<String,String>) -> Void)
{
let url1 = URL(string: urlStr)
var request = URLRequest(url: url1!)
let tokenId = fileMgr.getCacheData(constants.defaultsKeys.TOKEN_KEY) as! String
print("tokenId >> \(tokenId) , urlStr >> \(urlStr)")
request.httpMethod = "POST"
request.addValue("application/xml", forHTTPHeaderField: "Content-Type")
request.addValue("application/xml", forHTTPHeaderField: "Accept")
request.setValue("Basic \(tokenId)", forHTTPHeaderField: "Authorization")
request.timeoutInterval = 20000.0
var dict = Dictionary<String,String>()
let task = URLSession.shared.dataTask(with: request)
{data, response, error in }
Please advice