如何从reactjs应用程序向drupal 7网站发出http请求

问题描述 投票:0回答:1

我正在使用reactjs构建无头的应用程序,我的应用程序基本上在localhost:3000上运行,同时向远程drupal 7网站发出http请求。我已启用CORS并能够发出hppt POST请求进行登录,我已将会话ID,令牌保存到浏览器的本地存储中,但是当我尝试使用superagent向同一台服务器发出get请求但返回的响应为空时]]

{{nodes:Array(0)} nodes:Array(0)length:0__proto__:Array(0)proto

:Objectconstructor:ƒObject()defineGetter:ƒdefineGetter() defineSetter:ƒdefineSetter()hasOwnProperty:ƒhasOwnProperty()lookupGetter:ƒlookupGetter()lookupSetter:ƒlookupSetter()isPrototypeOf: isPrototypeOf()propertyIsEnumerable:ƒpropertyIsEnumerable()toString:ƒtoString()valueOf:ƒvalueOf()toLocaleString:ƒtoLocaleString()get proto:ƒproto()set proto: ƒproto()

我也向同一台服务器发出了类似的请求,但到了不同的端点,它返回了此错误:

从源'http://website.com/endppoint-json'对'http://localhost:3000'处XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态。client.js:890 GEThttp://website.com/endppoint-jsonnet :: ERR_FAILED

这是我的代码的样子:

superagent
      .get('http://website.com/endpoint-json')
      .set('Authorization', `Bearer ${this.getAuthenticationToken()}`)
      .end((err, res) => {
        if(err) {this.setState({errorMessage: 'Cannot retrieve geofences from server'}); return;}
        //this.setState({geofences: res.body});
        console.log(res.body);
      });

请问我有没有做正确的事,这是我第一次发出这样的http请求,确实给了我一个艰难的时刻,请帮助,而不是侮辱。

我正在使用reactjs构建无头的应用程序,我的应用程序基本上在localhost:3000上运行,同时向远程drupal 7网站发出http请求。我已启用CORS,并且...

json reactjs api cors superagent
1个回答
0
投票

我尝试过,尽管它没有发送到Drupal网站,但我认为这很酷

© www.soinside.com 2019 - 2024. All rights reserved.