相关疑难解决方法(0)

获取api不返回Location标头

这是我从chrome复制的标题Version 52.0.2743.82 (64-bit)(尚未确定它是否与chrome隔离)

Request URL:http://localhost:8080/users
Request Method:POST
Status Code:201 
Remote Address:[::1]:8080

Response Headers
view parsed
HTTP/1.1 201
Access-Control-Allow-Origin: http://localhost:9000
Vary: Origin
Access-Control-Allow-Credentials: true
X-Application-Context: application:xenoterracide,development
Location: http://localhost:8080/users/17
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Length: 0
Date: Thu, 18 Aug 2016 13:51:19 GMT

Request Headers
view parsed
POST /users HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 92
Pragma: no-cache
Cache-Control: no-cache
accept: application/json
Origin: http://localhost:9000
User-Agent: Mozilla/5.0 (X11; Linux x86_64) …
Run Code Online (Sandbox Code Playgroud)

google-chrome cors typescript aurelia fetch-api

5
推荐指数
1
解决办法
1140
查看次数

无法在 create-react-app 中看到 Content-Disposition 标头

我有一个 create-react-app,由 Express 提供服务。Express 仅充当该应用程序的代理。应用程序逻辑位于 CRA 中。

我正在尝试调用 API 并下载文件。API 使用包含文件名的“Content-Disposition”标头进行响应。我无法检索通话中的标头。

当我在 Postman/chrome-dev-tools 中调用 API 时,我可以看到可用的标头。

请参阅下面我的代码。文件名代码被注释掉,因为res.headers它是空的。

let filename = 'test-file-name'; // <--- default file name
const output = fetch(transactionReportPath(), {
    headers: {
      accept: 'text/csv',
      Authorization: `Bearer ${getToken()}`
    }
  })
    .then((res) => {
        console.log(res.headers) // <---- empty object
        // filename = res.headers.get('Content-Disposition').split(";")[1]
        return res.blob()})
    .then((blob) => {
      const file = window.URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = file;
      a.download = filename;
      document.body.appendChild(a); 
      a.click();
      a.remove();
    });
Run Code Online (Sandbox Code Playgroud)

javascript download reactjs

1
推荐指数
1
解决办法
2662
查看次数