反应本机投掷 406 "Not Acceptable" 仅用于 android

React native throwing 406 "Not Acceptable" for android only

我已将 zf3/laminas API 配置为获取 JSON 数据。它在 IOS 或网络模拟器中工作正常但在 android.

中不起作用

它抛出:

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",
}

这是 header zf3 发送反应:

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",
  },
}

我在反应中的功能:

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);
    }
  }

我做错了什么?

好吧,太蠢了。我有一些语法错误。

这是有效的:

      const dictionaryApiCall = await fetch(
            API_URL_INIT,
            {
                headers: { //add headers
                    'Accept': 'application/json',
                    'Content-type': 'application/json'
                }
            }
            );

希望这对某人有所帮助。