【问题标题】:How to change content-type in http-interceptor如何更改 http-interceptor 中的内容类型
【发布时间】:2015-11-16 10:43:38
【问题描述】:

我会在 http-interceptor 中为方法“request”更改内容类型?

我尝试了以下方法但没有成功:

 config.headers[Content-Type] = 'application/json, text/plain';

有解决办法吗?

代码:

'request': function(config) {
            config.headers[Content-Type] = 'application/json, text/plain';
            return config || $q.when(config);
        },

提前感谢您的回答!

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    您需要将数组引用键用引号括起来,例如

    config.headers['Content-Type']
    

    让它工作。

    【讨论】:

      【解决方案2】:

      也许你忘了用 $httpProvider 注册你的拦截器?

      angular.module('myApp', [])
        .config(function($httpProvider) {
        $httpProvider.interceptors.push('myInterceptor');
       });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-01
        • 2018-05-20
        • 2010-10-29
        • 1970-01-01
        • 2017-11-14
        • 2012-09-22
        • 2018-08-30
        • 2017-03-22
        相关资源
        最近更新 更多