ASP.Net WebAPI PDF表单提交的返回值 [英] ASP.Net WebAPI Return value for PDF Form Submit

查看:50
本文介绍了ASP.Net WebAPI PDF表单提交的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获取Asp.net Webapi来为提交pdf表单返回正确的响应?

How do I get my Asp.net webapi to return the correct response for a pdf form submit?

推荐答案

要将响应保留在pdf应用程序内部,您必须返回FDF格式的文件.

To keep the response inside of the pdf application you must return an FDF formatted file.

使它起作用的关键是您不能仅仅返回一个字符串.您必须首先将其编码为内存流,并且标头必须设置为 application/vnd.fdf .

The key to get this to work is that you cannot just return a string. You must first encode it to a memory stream and the header must be set to application/vnd.fdf.

这是示例代码:

Public Function PostValue(<FromBody()> ByVal value As MyPDFFieldsObject) As HttpResponseMessage
        Dim fdfmessage As String = "%FDF-1.2" & vbCrLf & _
                "1 0 obj <<" & vbCrLf & _
                "/FDF <<" & vbCrLf & _
                "/Status (Submitted Successfully!)" & vbCrLf & _
                ">>" & vbCrLf & _
                ">>" & vbCrLf & _
                "endobj" & vbCrLf & _
                "trailer" & vbCrLf & _
                "<</Root 1 0 R>>" & vbCrLf & _
                "%%EOF"
        Dim result As HttpResponseMessage = New HttpResponseMessage(HttpStatusCode.OK)
        Dim stream As New MemoryStream(Encoding.UTF8.GetBytes(fdfmessage))
        stream.Position = 0
        result.Content = New StreamContent(stream)
        result.Content.Headers.ContentType = New MediaTypeHeaderValue("application/vnd.fdf")
        Return result
    End Function

这篇关于ASP.Net WebAPI PDF表单提交的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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