我可以通过Ionic发出Ajax JQuery POST请求吗? [英] Can I make an Ajax JQuery POST request with Ionic?

查看:397
本文介绍了我可以通过Ionic发出Ajax JQuery POST请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Ionic应用程序进行NTLM身份验证.使用邮差(一种测试请求的工具),我能够进行此身份验证,并且可以完美地工作(使用NTLM身份验证选项).

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).

但是,邮递员未提供任何代码来在Angular中实现此请求(对于Ionic).

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

进行了自己的研究后,我发现 Angular 2及更高版本不支持NTLM身份验证.真的是这样吗?

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

所以我在想用Jquery和下面的代码(由邮递员生成)生成我的请求. 但是它可以与Ionic一起使用吗?

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

这是Postman为该请求生成的JQuery Ajax实现:

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);
}); 

推荐答案

最后,我发现了.来自邮递员的javascript代码无法正常工作,因此我只是在Angular中发出了一个简单的POST请求,并且将http://username:password@myserver.com用作了url.现在可以正常使用了!

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 !

参考资料:使用Javascript验证Windows身份验证

此外,为帮助处于相同情况并在使用ionic serve时遇到CORS问题困扰的人们,只需禁用chrome中的chrome web安全即可.真正的设备,CORS应该不会有任何问题.

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.

感谢您的帮助

这篇关于我可以通过Ionic发出Ajax JQuery POST请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆