Spring @Controller方法返回奇怪的下载异常

时间:2015-07-08 23:11:41

标签: java spring spring-mvc

我在Spring MVC应用程序中返回了一个奇怪的错误。当我尝试通过@RestController方法保存用户时,浏览器似乎将该操作解释为下载应用程序的请求。有关此问题的一些信息:

  • 仅当我的应用程序部署到远程服务器上时(在本地按预期工作)才会返回
  • 这仅在Internet Explorer中发生

这是错误:

enter image description here

详细...

OPERATION PROGRESS STATUS
    * [7/8/2015 6:56:16 PM] : Activation of mySite.com/myApp/saveUser/100 has started.

ERROR DETAILS
    Following errors were detected during this operation.
    * [7/8/2015 6:56:17 PM] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
        - Downloading mySite.com/myApp/saveUser/100 did not succeed.
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
            at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
            at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
            at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options)
            at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
            at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
        --- Inner Exception ---
        System.Net.WebException
        - The remote server returned an error: (405) Method Not Allowed.
        - Source: System
        - Stack trace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

这是我的控制器:

@RequestMapping(value = "/saveUser/{id}", method = RequestMethod.POST)
    public String saveUser(@ModelAttribute("user") User user, @PathVariable Long id, Model model) {
        model.addAttribute("user", user);
        userRepo.save(user);
        return "success";
    }

该方法非常简单,我没有指定任何响应标头。有什么想法可能会发生这种情况吗?

UPDATE 捕获网络流量时,远程服务器上的POST方法类型为application/x-ms-application,其中Type为本地计算机上的标准text/html

1 个答案:

答案 0 :(得分:0)

明确将produces属性设置为"text/html"似乎已解决此问题

@RequestMapping(value = "/saveUser/{id}", produces="text/html", method = RequestMethod.POST)

来自Spring Docs

  

使用生成条件可确保实际使用的内容类型   生成响应尊重在中指定的媒体类型   产生条件

相关问题