提示浏览器从App Engine保存JSON HTTP响应?

时间:2018-06-07 20:58:38

标签: json angular http

TL,DR; HTTP请求/响应标头(下面粘贴)中是否有任何内容阻止浏览器打开保存对话框?

我希望浏览器在从App Engine收到JSON HTTP响应时提示用户'另存为'

使用案例

  1. 网络应用程序用户点击按钮下载当前在Angular组件中呈现的JSON。
  2. HTTP POST使用JSON在正文中发出请求。
  3. Golang App Engine接收HTTP请求,并使用相同的JSON进行响应。
  4. HTTP响应应触发浏览器提示用户另存为...
  5. 请求标题

    :authority: my-app.appspot.com
    :method: POST
    :path: /download
    :scheme: https
    accept: application/json, text/plain, */*
    accept-encoding: gzip, deflate, br
    accept-language: en-US,en;q=0.9
    cache-control: no-cache
    content-length: 2030
    content-type: application/json
    origin: https://my-app.appspot.com
    pragma: no-cache
    referer: https://my-app.appspot.com/
    user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
    

    响应标题

    access-control-expose-headers: Content-Disposition
    cache-control: private
    content-disposition: attachment;filename=export.json
    content-encoding: gzip
    content-length: 466
    content-type: application/json
    date: Thu, 07 Jun 2018 20:42:14 GMT
    server: Google Frontend
    status: 200
    vary: Accept-Encoding
    

    Angular Service发起请求:

    @Injectable({
      providedIn: 'root'
    })
    export class DownloadService {
    
      constructor(private readonly http: HttpClient) {}
    
      public download(request: DownloadRequest): Observable<DownloadResponse> {
        const url: string = 'https://my-app.appspot.com/download';
        const httpOptions = {
          headers: new HttpHeaders({
            'Content-Type': 'application/json'
          }),
          options: {
            responseType: ResponseContentType.Json
          }
        };
    
        return this.http.post<DownloadResponse>(url, request, httpOptions);
      }
    }
    

    没有错误,但浏览器提示用户下载。

    的everythin

0 个答案:

没有答案