getXMLHeaders(): Headers {
const headers = new Headers({
'Authorization': `Basic ${localStorage.getItem('APIkey')}`,
'content-type': 'text'
});
return headers;
}
getOptionsXML(): RequestOptions {
const options = new RequestOptions({headers: this.getXMLHeaders()});
return options;
}
writeXML(file: string, xml: any, http: Http): boolean {
try {
const options = this.getOptionsXML();
const body = {
'path': file,
'body': xml
};
console.log(body);
const readFile = http.post(LOCAL_API_ADDRESS
+ localStorage.getItem('APIport')
+ '/local-api/write-File/', body, options)
.toPromise();
readFile.then(res => {
})
.catch(err => {
this.loggerServer.error(http, 'writeXML() promise error: '
+ err.message);
});
return true;
} catch (err) {
this.loggerServer.error(http, 'FileManager writeXML: ' + err.message);
return false;
}
}
答案 0 :(得分:0)
在内容类型中,您通知端点您要发送的数据类型。如果你说它是XML(text / xml,application / xml)并且服务器不接受这种格式,则会产生500.显然你的端点只接受JSON(application / json)。
简单地说,您正在尝试以这种格式发送消息:
<content>
<param Name="ParamA">TextA</text>
</content>
虽然服务器只接受这种格式:
{
"ParamA":"TextA"
}