wymsee / cordova-HTTP

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!
MIT License
371 stars 300 forks source link

Requesting Step By Step usage guide by calling your plugin from javascript? #108

Open ehaab opened 8 years ago

ehaab commented 8 years ago

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.

Tyron199 commented 8 years ago
cordovaHTTP.post(%API_URL%, {
  var1: 1,
  var2: "2"
}, { }, function(response) {
  console.log(response.status);
}, function(response) {
  console.error(response.error);
});
ehaab commented 8 years ago

@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?

mike-roberts commented 7 years ago

@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');