HTTP请求415错误 – 不支持的媒体类型(Unsupported media type)

HTTP请求415错误 – 不支持的媒体类型(Unsupported media type)
使用AJAX传输数据发生415错误,在ajax中设置请求头部信息就解决了。

$.ajax({
        url : url,
        type:'POST',
        dataType: 'JSON',
        data: JSON.stringify(addItem),
        xhrFields: {
            withCredentials: true
        },
        beforeSend : function(req) {
            req.setRequestHeader('Authorization', auth);
            req.setRequestHeader('Content-Type', 'application/json');  ///加这一行解决问题
        },
        success: function(data) {
            console.log(data);
        },
        error: function(){
            console.log('error');
        }
    });

你可能感兴趣的:(HTTP请求415错误 – 不支持的媒体类型(Unsupported media type))