[英]Calling spring boot webservice from angularjs with get method, is not working is giving 500 status error
I have created a webservice to get the excel file from server location to my local machine.我创建了一个 Web 服务来将 excel 文件从服务器位置获取到我的本地计算机。 with the help of springboot and angularjs.
在 springboot 和 angularjs 的帮助下。 Now my URL is generating well, but i am getting 500 error.
现在我的 URL 生成良好,但我收到 500 错误。 my code is given below..
我的代码如下..
My Springboot class:我的 Springboot class:
class MyWebserviceClass
{
@RequestMapping(method = RequestMethod.GET, value = "digital_data/{digital_file}", produces = "application/vnd.ms-excel")
public getExcelFileFromServer((HttpServletResponse response, @PathVariable("digital_file") String digital_file) throws IOException {
{
// my download logic will we here
}
AngularJS controller method AngularJS controller 方法
digitalService.getDigitalData(digital_file).then (function(res) {
var blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
saveDigitalData(blob, digital_file);
}, function(errRes) {
$scope.showErrorMessage("Error");
})
};
AngularJS Service Layer AngularJS 服务层
digitalService
{
function getDigitalData(digital_file) {
var url = 'digital_data/'+file_name;
return $http.get(url,{
transformRequest: angular.identity,
headers: {'Content-Type': undefined},
responseType:"arraybuffer"
});
}
}
After running this code, web service URL generating properly but code is not able to call springboot webservice.运行此代码后,web 服务 URL 生成正常,但代码无法调用 springboot webservice。
Generated URL: http://localhost:8080/RMS/digital_data/user_review.xlsx生成的URL: http://localhost:8080/RMS/digital_data/user_review.xlsx
Error:错误:
{resStatus: -3, appErrorMsg: "Could not find acceptable representation"} {resStatus:-3,appErrorMsg:“找不到可接受的表示”}
Exception: com.media.MediaController.MyWebservice.getExcelFileFromServer(javax.servlet.http.HttpServletResponse,java.lang.String) throws java.io.IOException={[/digital_data/{digital_file}],methods=[GET],produces=[application/vnd.ms-excel]}} Exception: com.media.MediaController.MyWebservice.getExcelFileFromServer(javax.servlet.http.HttpServletResponse,java.lang.String) throws java.io.IOException={[/digital_data/{digital_file}],methods=[GET],produces =[应用程序/vnd.ms-excel]}}
could you guys please help me, as this is my first webservice.你们能帮帮我吗,因为这是我的第一个网络服务。 it might be possible i am doing some silly mistake.. And sorry for typo mistake...
可能我犯了一些愚蠢的错误..抱歉错字错误...
I removed the file extension from the filename for URL, and added into springboot functionality.我从 URL 的文件名中删除了文件扩展名,并添加到 springboot 功能中。 Example: URL would be http://localhost:8080/RMS/digital_data/user_review instead of http://localhost:8080/RMS/digital_data/user_review.xlsx .. and it is working fine.
Example: URL would be http://localhost:8080/RMS/digital_data/user_review instead of http://localhost:8080/RMS/digital_data/user_review.xlsx .. and it is working fine.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.