【问题标题】:React native throwing 406 "Not Acceptable" for android only仅适用于 android 的 React native throwing 406“Not Acceptable”
【发布时间】:2020-07-04 09:22:32
【问题描述】:

我已将 zf3/laminas API 配置为获取 JSON 数据。它在 IOS 或 web 模拟器中运行良好,但在 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",
}

这是标头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);
    }
  }

我做错了什么?

【问题讨论】:

    标签: react-native zend-framework3 laminas-api-tools


    【解决方案1】:

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

    这是有效的:

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

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 2018-07-31
      • 2013-08-10
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多