[英]HTTP Status 406 – Not Acceptable in spring MVC Rest Service
這是我的代碼:
@RequestMapping(value = "/report/download", method = RequestMethod.GET,produces="application/vnd.ms-excel")
public Response getReportFile(@QueryParam("reportid") Long reportId)
{
System.out.println("Param"+reportId);
Long n=(long) 10;
String json=reportService.getReportFile(n);
File file = new File("D:\\Agent Information.xls");
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition","attachment; filename=Sample.xls");
return response.build();
}
我在Java控制台中收到以下錯誤:處理程序執行導致異常:找不到可接受的表示形式
您的網絡服務說您的客戶端請求中的“ Accept HTTP header
中未提供返回的響應類型。
因此,在發出HTTP請求時,您必須添加'Accept Headers'。 如果是JSON
請求,則將添加'Accept : application/json'
。 同樣,對於您當前的示例,它將是
'Accept: text/plain'
'Accept-Charset: utf-8'
在此處找到所有接受標頭 。 並按照以下步驟解決
1)找出Web服務返回的response (content type)
。
2)在您的請求Accept標頭中提供此(內容類型)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.