简体   繁体   English

使用 get 方法从 angularjs 调用 spring 引导 web 服务,不起作用是给出 500 状态错误

[英]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.

相关问题 为什么从Ajax调用Web服务会引发内部服务器500错误? - Why calling a webservice from ajax throws internal server 500 error? 调用 Spring 引导 api 从 Angular 6 下载 pdf 给出错误无法解析响应 - Calling Spring boot api that downloads a pdf from Angular 6 is giving error can't parse response 如何在 POST 方法中获取失败时从 express 而不是状态 500 中获取实际错误? - How to get the actual error from express instead of status 500 in React on failed fetch in POST method? Spring MVC,AngularJS错误500 - Spring MVC ,AngularJS error 500 从JavaScript调用网络服务-错误500 - Call webservice from JavaScript - error 500 在Spring Boot应用程序中从Angular JS调用Rest Services时出错 - Error in calling Rest Services from Angular JS in a Spring Boot application 从Javascript / jQuery调用PHP Webservice方法 - Calling PHP webservice method from Javascript/jQuery JQuery Ajax-Request错误500找不到Web服务方法 - Webservice method not found by JQuery Ajax-Request error 500 调用网络服务时如何编写单独的错误方法? - how to write separate error method while calling calling webservice? jQuery未在firefox浏览器中调用Webservice方法,并且在Chrome和IE中运行良好 - Jquery not calling Webservice method in firefox browser and it is working good in Chrome and IE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM