问题标签 [isomorphic-fetch-api]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
461 浏览

javascript - 使用 fetch() 向 Instagram API 发出 POST 请求,引发错误

我正在使用fetch从 Instagram API 检索数据以进行授权

需要访问令牌以响应请求。

但是,出现错误: {"error_type": "OAuthException", "code": 400, "error_message": "You must provide a client_id"}

0 投票
1 回答
647 浏览

django - 2 个 docker 容器(Django 和 React),isomorphic-fetch 和一个登录请求

我的设置在带有前端(React)和后端(Django)容器的 Docker 上运行。

我在另一个项目中使用下面的 drf-react-app 的登录表单组件,并且对于 loginUser 操作创建器(src/actions/user.js)中的 api 获取请求如何知道它应该是哪个 URL 一无所知使用..?

我希望它将请求发送到端口 8000 的服务器。我从这个 drf-react 样板中获取了代码:https ://github.com/moritz91/drf-react-login

我错过了什么?

0 投票
1 回答
16354 浏览

javascript - ReactJS无法读取未定义的属性setState

我是 ReactJS 的新手,并且有点理解这个问题与 SOF 中的数字问题重复。

但我希望有人能给我一些关于 React 概念的指导和澄清。

我想要做的只是使用axiosisomorphic-fetch在加载屏幕之前从远程 REST API 获取数据。

但是,我看到了很多类似的 React 教程,我仍然没有明白这一点。

这是我的代码:

以下是我的问题:

  • 我想在显示整个 UI 之前加载列表,这段代码中缺少什么?
  • 在这里使用箭头功能是否正确getLUISIntent
  • 我可以用async/awaitgetLUISIntent()吗?
  • 对我来说,async/await意味着在执行下一个“行”之前等待函数的响应。这个概念正确吗?
  • 如果我需要写一个额外this.__my_fancy_function__ = this.__my_fancy_function__.bind(this)的使用类函数,使用箭头函数似乎写的代码更少,更易读,为什么不是每个人都使用它?
  • 那里有Fetch remote API before loading anything using ReactJS tutorial no splitting different component but showing everything in only single App.js No BS so that everyone can see how a REST API-simple ReactJS app is run教程吗?如果没有这样的东西,我想写它。但在此之前,我希望有人能先帮助我理清思路。

非常感谢您的帮助。

0 投票
0 回答
154 浏览

javascript - 当凭据设置为“同源”时,同构提取不传递文件

我正在使用同构 fetch并使用Formdata

当我尝试使用 isomorphic-fetch-api 发布/请求表单数据时,有两种情况是关于docs的意外行为。(注意:这里的formdata包括文件对象)

  1. 添加 时credentials: include,请求在没有 cookie 的情况下传递。(并且后端和前端在同一台服务器上运行,因此可能不需要添加“包含”)
  2. 添加时credentials: same-origin,cookies 被传递。但是在这种情况下我面临的问题是formdata。使用 formdata(包括文件对象)传递数据时,发布到后端的数据不包括文件对象,其余值可用。

第三种情况,当不添加凭据时,没有 cookie 传递,没有 cookie 什么也做不了。

不太确定是什么导致了 Formdata 或 Fetch 或 Credentials 的这种行为。请帮助我了解我的方法中是否缺少某些东西。

0 投票
0 回答
175 浏览

javascript - 在 GET 调用中使用 isomorphic-fetch 时基本身份验证无法正常工作

WWW-Authenticate:Basic realm="Realm"在标头中正确传递身份验证参数,但它会在响应标头中转换为。

下面是我的 get api 调用代码片段。

调用 api 后出现错误 401。邮递员工作正常。

我也尝试过使用普通的 jquery ajax 调用,但仍然无法得到它。

仍然收到 401 错误。

0 投票
1 回答
1195 浏览

reactjs - Asp.net core 2.0 react.js cookie认证同构-获取无限循环

我有一个带有 react.js 的小型 asp.net 核心应用程序,它使用 cookie 身份验证对用户进行身份验证。当我直接调用控制器的操作时,似乎 cookie 身份验证工作正常。

例如,如果我输入http://localhost/Test/Index它会按预期工作。进行身份验证并创建 cookie,并在后面的请求中使用 cookie。

但是,当我的 react 组件使用 isomorphic-fetch 调用控制器方法时,它会变成无休止的身份验证循环。

这是我的startup.cs

这是我验证用户的地方。(AccountController/Login)

这是我创建无限登录循环的 fetch 方法。

0 投票
1 回答
539 浏览

reactjs - 使用 Isomarpic-fetch 获取 POST API 时忽略标头

后端服务器:使用 spring OAuth 2 实现 google 身份验证

因此,通过上述详细信息,我正在尝试如下所示的 api 端点,

这给了我一个状态码 302 并且标头永远不会设置为请求标头的一部分。除此之外,永远不会设置 cookie。

我浪费了整整 2 天的时间来理解为什么没有设置标题,并且在 SO 和 github 上浏览了许多帖子,但我们都没有帮助我。

因此,非常感谢任何帮助。

谢谢,基兰

0 投票
1 回答
666 浏览

node.js - unable to display data using fetch API - node.js

So, I am getting the below error,

inspected via google chrome

enter image description here

What I am trying to achieve is to explore the Fetch Api by retrieving some data via userApi.js file which pulls it from a srcServer.js (I have hardcoded some data here). I am using webpack bundle and index is the entry point of my project. I have created index.html to bind the data via innerhtml.

Earlier I was using import 'isomorphic-fetch' in my userApi.js file but that too didn't help and hence I found some suggestions on google to use isomorphic-fetch, node-fetch etc. nothing of that sort worked.

I have added most of the artifacts below can you please guide me what is that I am missing here.

Project Structure

enter image description here

userApi.js

index.js

index.html

srcServer.js

0 投票
4 回答
1276 浏览

javascript - 如何从 reactjs 和 API 中检索数据

我正在尝试将表单数据从反应发布到节点后端,该怎么做?我的反应代码是:

我的 NodeJs 代码

如何检索数据

0 投票
1 回答
6675 浏览

node.js - 在 NodeJS + Express 中向 get 请求添加“x-api-key”标头的最佳方法是什么?

我想发送一个获取请求,但我需要将我的 api 密钥插入到“x-api-key”标头中。我正在使用 NodeJS + Express。现在我正在使用“isomorphic unfetch”库中的 fetch:

https://github.com/developit/unfetch/tree/master/packages/isomorphic-unfetch

我使用它来从 get 请求中获取数据。我特别使用这个库,因为它在服务器和客户端上都运行良好。

我应该如何将标头添加到我的请求中?谢谢!