编辑:下面描述的问题是我使用的api的问题.跟阿波罗没什么问题。
我正在尝试使用apollo-link-rest,并在头中设置api-key。如果我尝试使用完全相同的api端点,并在Postman应用程序中将api键设置为标头,它的工作非常好。但对apollo-link-rest来说不是
import { AppContainer } from 'react-hot-loader';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './react-components/App';
import PropTypes from 'prop-types';
import { RestLink } from "apollo-link-rest";
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import 'normalize.css/normalize.css';
import './index.css';
const restLink = new RestLink({
uri: 'https://a-site.net/api',
headers: {
'x-someapikey': '012737465334232522z2z22163r43'
},
});
const client = new ApolloClient({
link: restLink,
cache: new InMemoryCache(),
});我做错什么了?
这就是在中打印的请求头:

我在浏览器(阿波罗)中有一个401错误.但当我在邮递员应用程序中使用相同的端点时.它起作用了!
发布于 2018-10-16 20:12:26
这是API的问题..。不是和阿波罗。
发布于 2018-10-13 15:48:23
你能试试这个吗?我的回答是基于这样的:https://www.apollographql.com/docs/link/links/rest.html#context
var myHeaders = new Headers();
myHeaders.append('x-someapikey', '012737465334232522z2z22163r43');
const restLink = new RestLink({
uri: 'https://a-site.net/api',
headers: myHeaders
});https://stackoverflow.com/questions/52631336
复制相似问题