'advanced-http: "data" option is configured to support only following data types: object
in ionic 5 (capacitor 3 , angular 12) project , i used ionic-native/http for send http request. when use http.post for send FormData object to server
var fd = new FormData();
fd.append('mobile', mobile);
this.http.post(url,fd,{})
show this error:
advanced-http: "data" option is configured to support only following data types: object
pleas help me.
extra explain: I had to use ionic-native/http. because when i used angular http-client , cancelled post methode and research it and i realized the problem of ssl certificate, set this code:
this.http.setServerTrustMode("nocheck")
Solution 1:[1]
Try this
import { HTTP } from '@ionic-native/http/ngx';
constructor(public http: HTTP){}
nativeAPIRequest(){
let params = {
app_version: '',
device_id: '',
community_id: '',
page_no: '',
results_per_page: '',
}
const options = {
method: method, // 'GET/POST'
data: params, // Post Method Parameter
headers: {}, // 'Content-Type': 'application/x-www-form-urlencoded', 'auth_token':''
responseType: 'json' as 'json',
timeout: 100.0
};
this.http.sendRequest(url, options).then(success => {}).catch(async error => {});
}
Solution 2:[2]
The one thing missing from Ravi Ashara response is:
this.http.setDataSerializer("urlencoded");
urlencoded: send data as url encoded content in body (content type "application/x-www-form-urlencoded")
This what I have:
import { HTTP } from '@ionic-native/http/ngx';
export class TokenService {
constructor(public http: HTTP){}
public getTokenData(): Observable {
this.http.setDataSerializer("urlencoded");
const httpCall = this.http.post(url, {
"grant_type": "client_credentials",
...
}, {});
return from(httpCall).pipe(
map(response => {
if (response.status === 200) {
return JSON.parse(response.data);
} else {
return response;
}
})
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Alex Matheson |