Hi i am trying to replicate a ios app in react-native.I am trying to make a get request with a authentication token in header. But getting below error : Exception has occurred: SyntaxError SyntaxError: Unexpected token < in JSON at position 0 at parse ()
I have tried following code :
let webPath = 'http://some.domain..svc/GetContactDetails?UserEmail=5555';
let request = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
//'Authorization': 'Bearer ' + myToken, // won't works same error
//'Token': myToken, // won't works same error
'Authorization':{'Token':myToken}
},
//credentials: 'include',
}
fetch(webPath, request)
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson)
})
.catch((error) => {
console.error(error);
});
In ios i am doing this using below code:
var request = URLRequest(url: url)
request.setValue("application/json", forHTTPHeaderField: "Accept")
let token_key = UserDefaults.standard.value(forKey: "token_key") as! String
request.setValue(token_key, forHTTPHeaderField: "Token")
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
Any help will really be apppreciated. Thanks in advance