我想将表单数据发布到接受并返回text / html / xml的服务器。我实际上是在尝试模仿普通的URL编码形式的POST。我的Angular 8 POST函数成功过帐(200 OK),但是服务器无法理解数据,因为它是JSON而不是URL编码。
响应和请求标头的状态为Content-Type: text/html; Charset=utf-8
和accept: text/html,application/xhtml+xml,*/*
,我已经在httpClient选项中添加了responseType: "text"
。为什么仍然向服务器发送JSON而不是向URL编码的数据?
// obj2 = output from ngForm
// baseUrl2 = server that sends and receives text/html/xml
public postForm(obj2) {
return this.httpClient
.post(this.baseUrl2,obj2,{
headers: new HttpHeaders({
"Content-Type": "application/x-www-form-urlencoded",accept: "text/html,*/*"
}),responseType: "text"
})
.map(data => data);
}
已发送表格数据:
{"Form data":{"{\"personsnameText\":\"name9\",\"centreEmailaddressText\":\"name9@name.com\",\"centreTelephoneNumberText\":123456789,\"centreNumberText\":\"ab123\",\"centreNameText\":\"ab123\",\"invoiceText\":\"123456789\",\"currencyText\":\"GBP\",\"amountText\":\"100\",\"cardtypeText\":\"Credit card\",\"commentsText\":\"Comments.\",\"declarationText\":true}":""}}
我想要什么:
personsnameText=name9?centreEmailaddressText=name9@name.com?centreTelephoneNumberText=123456789?centreNumberText=ab123?centreNameText=ab123?invoiceText=123456789?currencyText=GBP?amountText=100?cardtypeText=Credit card?commentsText=Comments.?declarationText=true