代码:
public HttpResponseMessage GetFileContent()
{
var md = new BaseModel();
try
{
platType = "1";
md = GeneratePDF();
}
catch (Exception ex)
{
md.AppMsg = ex.Message;
}
var response = Request.CreateResponse(HttpStatusCode.OK);
var data = JsonConvert.SerializeObject(md);
response.Content = new StringContent(data, Encoding.UTF8);
LogHelper.WriteInfo("*************************************************************************************");
LogHelper.WriteInfo("GetFileContent_data:" + data);
LogHelper.WriteInfo("GetFileContent_response.Content:" + response.Content);
LogHelper.WriteInfo("GetFileContent_Headers:" + response.Headers);
LogHelper.WriteInfo("GetFileContent_IsSuccessStatusCode:" + response.IsSuccessStatusCode);
LogHelper.WriteInfo("GetFileContent_StatusCode:" + response.StatusCode);
LogHelper.WriteInfo("GetFileContent_ReasonPhrase:" + response.ReasonPhrase);
LogHelper.WriteInfo("GetFileContent_RequestMessage:" + response.RequestMessage);
LogHelper.WriteInfo("GetFileContent_Version:" + response.Version);
LogHelper.WriteInfo("*************************************************************************************");
return response;
}
不同的参数请求的返回结果:
2019-06-11 06:22:40,775 [6] [INFO ] : *************************************************************************************
2019-06-11 06:22:40,783 [6] [INFO ] : GetFileContent_data:{"AppMsg":"获取文件成功","AppCode":1,"Success":true,"Data":{"FileName":"f6faedad315a4a2c94bae52aedc7d06c.pdf","TmpPDFUrl":"http://127.0.0.1:9031/PrintService/DownloadFile?fileName=f6faedad315a4a2c94bae52aedc7d06c.pdf","TmpId":"30","TmpType":"在职证明","ECode":"R10119069658"}}
2019-06-11 06:22:40,791 [6] [INFO ] : GetFileContent_response.Content:System.Net.Http.StringContent
2019-06-11 06:22:40,799 [6] [INFO ] : GetFileContent_Headers:
2019-06-11 06:22:40,806 [6] [INFO ] : GetFileContent_IsSuccessStatusCode:True
2019-06-11 06:22:40,813 [6] [INFO ] : GetFileContent_StatusCode:OK
2019-06-11 06:22:40,829 [6] [INFO ] : GetFileContent_ReasonPhrase:OK
2019-06-11 06:22:40,842 [6] [INFO ] : GetFileContent_RequestMessage:Method: POST, RequestUri: 'http://localhost:9011/PrintService/GetFileContent', Version: 1.1, Content: System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent, Headers:
{
Connection: Keep-Alive
Expect: 100-continue
Host: localhost:9011
Content-Length: 252
Content-Type: application/json
}
2019-06-11 06:22:40,854 [6] [INFO ] : GetFileContent_Version:1.1
2019-06-11 06:22:40,861 [6] [INFO ] : *************************************************************************************
2019-06-11 06:22:53,661 [6] [INFO ] : GeneratePDF_context:System.Web.HttpContext
2019-06-11 06:22:53,675 [6] [INFO ] : 【来自终端设备】GeneratePDF【入参】:{"TerminalNO":"101","TerminalIP":"127.0.0.1","TerminalType":"","Data":{"SerialNumber":"","TemplateNO":"61","PrintingTime":"","PrintArchive":"","ResultScreenshot":"","PrintState":"Success","ECode":"2019000141","Reason":"","UserCode":"M2018003"}}
2019-06-11 06:22:54,107 [6] [INFO ] : EnglishGradeInfo_ProcessRequest_context:System.Web.HttpContext
2019-06-11 06:22:54,593 [6] [INFO ] : 【来自终端设备】【PDF申请接口】【出参】:PDF文件申请成功
2019-06-11 06:22:54,598 [6] [INFO ] : *************************************************************************************
2019-06-11 06:22:54,604 [6] [INFO ] : GetFileContent_data:{"AppMsg":"获取文件成功","AppCode":1,"Success":true,"Data":{"FileName":"c20644eb351b4e12becf9f215887a1d7.pdf","TmpPDFUrl":"http://127.0.0.1:9031/PrintService/DownloadFile?fileName=c20644eb351b4e12becf9f215887a1d7.pdf","TmpId":"61","TmpType":"英文成绩单","ECode":"20190611062254"}}
2019-06-11 06:22:54,609 [6] [INFO ] : GetFileContent_response.Content:System.Net.Http.StringContent
2019-06-11 06:22:54,616 [6] [INFO ] : GetFileContent_Headers:
2019-06-11 06:22:54,624 [6] [INFO ] : GetFileContent_IsSuccessStatusCode:True
2019-06-11 06:22:54,630 [6] [INFO ] : GetFileContent_StatusCode:OK
2019-06-11 06:22:54,635 [6] [INFO ] : GetFileContent_ReasonPhrase:OK
2019-06-11 06:22:54,641 [6] [INFO ] : GetFileContent_RequestMessage:Method: POST, RequestUri: 'http://localhost:9011/PrintService/GetFileContent', Version: 1.1, Content: System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent, Headers:
{
Expect: 100-continue
Host: localhost:9011
Content-Length: 248
Content-Type: application/json
}
2019-06-11 06:22:54,646 [6] [INFO ] : GetFileContent_Version:1.1
2019-06-11 06:22:54,655 [6] [INFO ] : *************************************************************************************
返回结果(日志中记录的一切正常):
正常返回结果(第一次请求):
开始本次请求:20190611 06:22:31
{"AppMsg":"获取文件成功","AppCode":1,"Success":true,"Data":{"FileName":"f6faedad315a4a2c94bae52aedc7d06c.pdf","TmpPDFUrl":"http://127.0.0.1:9031/PrintService/DownloadFile?fileName=f6faedad315a4a2c94bae52aedc7d06c.pdf","TmpId":"30","TmpType":"在职证明","ECode":"R10119069658"}}
本次请求结束:20190611 06:22:40
本次请求耗时9155.8157ms
非正常返回结果(第二次请求):
开始本次请求:20190611 06:22:52
本次请求结束:20190611 06:22:54
本次请求耗时1997.5708ms
日志中记录的一切正常,但是用HttpPost请求之后,返回的结果一个正常,一个为空。其中GeneratePDF()有两种实现方式,一种是word直接转的PDF,该访问方式完全正常,另外一种,反射访问的类库,但是返回结果为空。
折磨了两天了,烦请大神给点建议,看看到底怎么回事?