0

I am currently struggling to create an AJAX request to an endpoint. I tried to fire the equivalent CURL GET command as below:

CURL-k -H "Some header" https://some API URL/Method

This works as I disabled SSL validation using -k. I know this should not be done, but I am okay with it.

The problem is that I want to fire the same using an AJAX call. I would like to know if this is really possible, and if so, can someone help me with the syntax. Also, I am using a proxy server in my AJAX call.

$.ajax({
  url: "https://proxyurl/https://some API URL/Method",
  success: function(result) {
    //Some code here
  }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • Yes it's possible, although you need to add your header still, [like this](https://stackoverflow.com/questions/7686827/how-can-i-add-a-custom-http-header-to-ajax-request-with-js-or-jquery), and ensure that the proxy is forwarding that header on. If you have a specific issue with any of this please add more detail to the question. I'm a little confused about the title though, as none of this is related to SSL in any way – Rory McCrossan Jan 29 '20 at 15:39
  • Thanks @RoryMcCrossan. I have the required headers in the ajax call as below: `$.ajax({ headers: { 'x-vault-token': 'Token value' } url: "https://proxyurl/https://some API URL/Method", success: function(result) { //Some code here } });` – shubhankar881 Jan 29 '20 at 15:58
  • Just to clear more about my question, I want to pass the equivalent -k parameter of CURL to make sure SSL verification is turned off. – shubhankar881 Jan 29 '20 at 16:02
  • There is no such equivalent in AJAX. – Rory McCrossan Jan 29 '20 at 16:03
  • Thanks for a prompt reply. Do we have any other way to call a REST API in web pages? – shubhankar881 Jan 29 '20 at 16:06
  • No. AJAX is it. As I said above though, so long as the SSL certificate is valid, then the request will work and the `-k` flag is redundant. If the SSL cert is not valid then you should fix that first. – Rory McCrossan Jan 29 '20 at 16:08

0 Answers0