You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过JavaScript/React Native读取API,浏览器与Java可正常访问

问题:API在浏览器可正常访问,但JavaScript/React Native调用失败
  • API地址:https://www.planete-sorties.net/api/api/ressources/types,在浏览器中可正常访问,但React Native应用调用时出现错误:[TypeError: Network request failed],同时在reqbin中测试该API也报错。
  • 后端Spring Boot接口实现代码:
@RequestMapping(value = URL_RESOURCES_TYPES, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getTypes() {
    String serviceResult = paramService.getTypes().toString();
    return ResponseEntity.ok().body(serviceResult);
}
  • 以下Java代码可正常读取该API:
UriComponentsBuilder uriBuilder = 
UriComponentsBuilder.fromHttpUrl(appendHost(URL_RESOURCES_TYPES));
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(null, getHeaders());
RestTemplate restTemplate = restTemplateConfig.restTemplate();
ResponseEntity<String> serviceResultRE = restTemplate.exchange(uriBuilder.toUriString(), HttpMethod.GET, requestEntity, String.class);

内容的提问来源于stack exchange,提问作者anon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 12:20:50