Open ehaab opened 8 years ago
cordovaHTTP.post(%API_URL%, {
var1: 1,
var2: "2"
}, { }, function(response) {
console.log(response.status);
}, function(response) {
console.error(response.error);
});
@Tyrson .Thanks that helped me alot. How I can send user agent via post request ? Is there a way to use this plugin to get html source code of remote website (just like php curl get data) ?How?
@ehaab two ways. First way, you will have to do it every time you make a post request.
cordovaHTTP.post('https://urlofapi', {
// Data object.
}, {
// Headers object.
'User-Agent': 'useragentstring'
}, function (response) {
// Success callback.
}, function (response) {
// Error callback.
}
Second way, this will set the user agent for all future requests
cordovaHTTP.setHeader('User-Agent', 'useragentstring');
I am struggling using your plugin on phonegap android project to make json post request to server. I appreciate if you show me how i can call your plugin from JavaScript and pass it two variables and API URL(to make post request) and get response back in JavaScript(response is json ) ! Thanks in advance.