我只想下面一个JSONObjects发送到我的API后端:
{
"username":"alex",
"password":"password"
}
所以我写了下面的功能,采用了棱角分明的$ HTTP:
$http(
{
method: 'POST',
url: '/api/user/auth/',
data: '{"username":"alex", "password":"alex"}',
})
.success(function(data, status, headers, config) {
// Do Stuff
})
.error(function(data, status, headers, config) {
// Do Stuff
});
我读在POST方法Content-Type头将被自动设置为“应用程序/ JSON”文档。
但我意识到,我在我的后端(Django + Tastypie)api上收到的内容类型是“text/plain”。
这会导致我的API无法正确响应此请求。我应该如何管理这种内容类型?
您的后端如何检索细节? – BKM
我使用Django Tastypie作为我的后端。我在$ http发送的内容类型中看到text/plain。 raw_post_data或POST数据也是空的。 –
所以很奇怪......如果我把标题:{'Content-Type':'application/x-www-form-urlencoded; charset = UTF-8'}它工作..但是,如果我把应用程序/ JSON ...它不是... –