如何使用javascript/js使用多个url向发送多个get请求
我的要求是我有多个url,需要逐个测试get方法才能得到响应 下面的URL示例 1-https:scgncp.com/12041/。 2-https:ibm.com/120024/。 ..... ....... ....... ...... ...... ..... ...... 100-没有fo URL 测试使用如何使用javascript/js使用多个url向发送多个get请求,javascript,jquery,angular,Javascript,Jquery,Angular,我的要求是我有多个url,需要逐个测试get方法才能得到响应 下面的URL示例 1-https:scgncp.com/12041/。 2-https:ibm.com/120024/。 ..... ....... ....... ...... ...... ..... ...... 100-没有fo URL 测试使用 $http(url).then(function(response) { //write status of response },function errorfunction(r
$http(url).then(function(response)
{
//write status of response
},function errorfunction(response){
//error status code should be display here
}
需要使用上述方法或其他方法测试100个URL。请帮助我您需要构建一个承诺数组并使用:
Promise.all(arrayOfPromises)
您可以在如何使用$q
发送多个异步调用中找到
以下是想法:
var urlList = ["url1","url2","url3"];
$q.all(urlList.map(function (url) {
return $http({
method: 'GET',
url: url
});
}))
您可以使用循环来循环所有
URL
,并对每个URL发出请求:
var urls = ["https:scgncp.com/12041/", "https:ibm.com/120024/"];
urls.forEach(function(url) {
console.log("Sending a request to: " + url);
$http(url).then(function(response) {
//write status of response
}, function errorfunction(response) {
//error status code should be display here
});
});
循环怎么样?如果你想激励人们帮助你,请花点时间写一个正确的问题。现在看看。