I have got zf3/laminas
API
configured to fetch JSON data. It is working fine in IOS or web simulator but doesn't work in android.
It throws:
Object {
"detail": "Unable to resolve Accept header to a representation",
"status": 406,
"title": "Not Acceptable",
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
}
This is the header zf3
sending to react:
Headers {
"map": Object {
"access-control-allow-headers": "Authorization, Origin, X-Requested-With, Content-Type:application/json, Accept:*",
"access-control-allow-methods": "PUT, GET, POST, PATCH, DELETE, OPTIONS",
"access-control-allow-origin": "http://localhost:4200",
"cache-control": "public, max-age=0",
"cf-cache-status": "DYNAMIC",
"cf-ray": "5ad7bbb47f45db28-KIX",
"cf-request-id": "03bab3a4ce0000db282798b200000001",
"connection": "keep-alive",
"content-type": "application/problem+json",
"date": "Sat, 04 Jul 2020 09:13:57 GMT",
"server": "cloudflare",
"vary": "Accept-Encoding,User-Agent",
"x-powered-by": "PHP/7.2.30",
},
}
My function in react:
async componentDidMount() {
try {
const call = await fetch(API_URL_INIT, [{'accept':'application/json', 'content-type':'application/json'}]);
console.warn(call.headers);//.get('Access-Control-Allow-Origin'));
const resp = await call.json();
} catch(err) {
this.setState({error: true});
console.log("Error fetching data-- ---------", err);
}
}
What am I doing wrong?
Ok, so so stupid. I had some syntax errors.
This is working:
const dictionaryApiCall = await fetch(
API_URL_INIT,
{
headers: { //add headers
'Accept': 'application/json',
'Content-type': 'application/json'
}
}
);
Hope this helps someone.