下载由java webservice(POST)流式传输的pdf [英] Download a pdf streamed by a java webservice (POST)

查看:104
本文介绍了下载由java webservice(POST)流式传输的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过POST方法调用的web服务:

I have a webservice that is called by POST method :

  @Path("/ficheAction/")
  @POST
  @Consumes({ MediaType.APPLICATION_JSON })
  @Produces("application/pdf")
  public Response ficheAction(final ParamSyntheseFicheActionDto paramSyntheseFicheAction) throws EngineException {
  [...]
     return Response.ok(output.toByteArray(), "application/pdf")
        .header("content-disposition", "attachment; filename = " + name + ".pdf").build();
  }

此网络服务使用我的js中的参数(Json):

This webservice use the parameters (Json) from my js :

  [...]    
  $.ajax({
        url : webServiceUrl,
        // 
        type : "POST",
        // Content type to send to the server
        contentType : "application/json; charset=utf-8",
        data : pData,
        dataType : "json",
        success : pCallback,
        cache : false,
    });

webservice接口工作,但在客户端,导航器不会打开文件( pdf)。

The webservice seams to work, but on the client side, the navigator doesn't open the file (pdf).

我用GET测试而不是POST(简化属性),它可以工作,但不能在POST ...
当我看看chrome调试中web服务的响应,我可以看到响应以%PDF-1.5开头......但是下载没有开始...

I've test with GET instead of POST (simplifying the attributes), and it works, but not in POST... When i look at the response of the webservice in the chrome debug, i can see that there is a response starting with "%PDF-1.5"... But the download does not start...

我做错了什么?

推荐答案

你应该使用GET方法。

You should use GET method.

下载文件,不要使用ajax只需通过简单的链接调用你的web服务。

To download the file, do not use ajax just call your webservice by simple link.

<a href="http://your-server.com/ficheAction">Download</a>

或者使用那个简单的js脚本:

Or use that simple js script:

window.open("http://your-server.com/ficheAction");

这篇关于下载由java webservice(POST)流式传输的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆