Can I make an Ajax JQuery POST request with Ionic?

2019-08-26 09:02发布

问题:

I want to make an NTLM authentication from a Ionic app. Using postman (a tool to test requests), I was able to make this authentication, and it works perfectly (using NTLM Authentication option).

However, postman does not provide any code to implement this request in Angular (For Ionic).

After making my own research, I found out that Angular 2 and above does not support NTLM authentication. Is that really the case?

So I was thinkig about generating my request with Jquery and the code below (generated by postman). But will it work with Ionic ?

Here is the JQuery Ajax implementation generated by Postman for this request :

var form = new FormData();
form.append("Login", "yakeri");
form.append("Password", "elcimai77");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://myserver.com/MyService",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "Cache-Control": "no-cache",
    "Postman-Token": "50392b83-879b-43cb-ba2e-0b5ffc61e2f8"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
}); 

回答1:

Finaly, I found out. The javascript code from postman did not work so I just made a simple POST request in Angular and I used http://username:password@myserver.com for the url. It works perfectly now !

Reference : Authenticate Windows Authentication using Javascript

Also, to help people who can be in the same situation and are struggling with CORS issues while using ionic serve, just disable chrome web security in chrome. You should not have any problem with CORS with real devices.

Thanks for your help