Can I make an Ajax JQuery POST request with Ionic?

 ̄綄美尐妖づ 提交于 2019-12-25 01:45:44

问题


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



来源:https://stackoverflow.com/questions/51384937/can-i-make-an-ajax-jquery-post-request-with-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!