angular - got ERR::CONNECTION_TIMED_OUT from cordova to my mvc 5 web api while call from jsfiddle is no issue
问题描述
I got stucked for 2 days regarding this issue. I've deployed mvc 5 web api to my local iis (in my local pc). Then I'd like to call the /token function from my cordova, I always get error timeout.
I've tested it using jsfidle in here and in postman, both return the correct value.
I've installed cordova plugin whitelist, and allow CORS on my api code.
Here's my code to get the access token to my api.
var loginData = {
grant_type: 'password',
username: parmUsername,
password: parmPassword
};
$.ajax({
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
},
type: 'POST',
url: 'http://202.189.20.8:8081/api/v1/Token',
dataType:'json',
data: loginData
})
.done(function (response, textStatus, jqXHR) {
window.location.replace('views/mainpage.html');
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
})
I've changed also the data format using below code
var formBody = [];
for (var property in loginData) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(loginData[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
But I still got the same error. I've tried also use cordova plugin advanced http to call the api, but it didn't work.
Please advise, I really confused right now.
解决方案
对不起,请忽略。自己解决了。老实说,这是防火墙问题。2天后,我忘记检查防火墙。可怜的我。:(
阿芬
推荐阅读
- puppet - 如何在代理机器上检测 Puppet 代理故障“无法从远程服务器检索目录”
- symfony - 如何验证 EntityType 字段?
- c - Concorde 中的 KDTREE 可执行文件
- dictionary - 在 Ansible 中的两个单独的 dict 值之间使用条件
- objective-c - 增量读取 UIDocument 时使用哪个线程来执行异步文件访问使用块
- php - 支持 cookie 并启用 Javascript 来抓取合作伙伴网站?
- html - 如何在 ChartJS 上自定义面积图的数据标签?
- c - 当 x 是有符号整数且 x=1 时,找到一个值 y,例如 (x < y) == (-x > -y) 将是假的?
- python - 使用 pyparsing 解析可变数量的可选参数
- javascript - 对象是不可迭代的 JavaScript