【问题标题】:trying to make a GET request and return is PDF尝试发出 GET 请求并返回 PDF
【发布时间】:2020-04-18 18:44:21
【问题描述】:

我正在尝试发出 GET API 请求,返回应该是 PDF 这就是我正在做的事情

useEffect(() => {
    const fetchOffer = async () => {
      setIsError(false);

      try {
        const authorizationToken = await AsyncStorage.getItem(
          'authorizationToken',
        );

        const res = await RNFetchBlob.fetch('GET', `${WEBAPI_URL}/client/loans/latest/agreement`, {
          Authorization : `Basic ${authorizationToken}`,
          'Content-Type': 'application/pdf',
        })
        console.log(res)
      } catch (exception) {
        // TODO: can do error handling here, or elsewhere globally for the app
        if (exception === 401) {
          console.log('here',exception)
        } else {
          setIsError(true);
        }
      }
    }
    fetchOffer();
  }, []);

但是会抛出异常! 有任何想法吗?我究竟做错了什么 ? 还值得一提的是,在针对失眠症测试 API 时,它运行良好

谢谢

【问题讨论】:

标签: javascript react-native react-hooks


【解决方案1】:

我发现了问题,

这只是一个授权问题 没有正确通过它

代码本身没问题……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2013-07-17
    • 2017-05-29
    • 2011-12-11
    • 2019-02-09
    • 2018-06-11
    • 2014-01-29
    相关资源
    最近更新 更多