如何在Excel Vba中获取Http请求 [英] How Do I Get Http Request In Excel Vba
问题描述
嗨。
有一个网站http://sim.mci.ir/first-step即销售手机sim卡。
此站点中有一个函数向 http://sim.mci.ir/get-发送请求free-nums [ ^ ]并获取可用的数字。
i希望在vba(excel)中执行此功能并在单元格中保存数字。
但它不起作用!
即使我在vba中使用'Call CurrentWindow.execScript ...'这个ajax函数在html中工作:
hi.
there is a website "http://sim.mci.ir/first-step" that sale mobile sim cards.
there is a function in this site that sends request to "http://sim.mci.ir/get-free-nums[^]" and gets available numbers.
i want to do this function in vba (excel) and save numbers in cells.
but it doesn't work!
this ajax function in html works, even if i use 'Call CurrentWindow.execScript...' in vba:
var range='9129370';
$.ajax({url: 'http://sim.mci.ir/get-free-nums',data: {range: range},type: 'GET'}).done(function (response) {
response = JSON.parse(response);
var unsortedNumbers = response.numbers;
if (response.status != 'OK') {
$('.suggestion-failed').html('No Service').show();
return;};
if (unsortedNumbers.length == 0) {
$('.suggestion-failed').html('No Range').show(); return;};
var bestMatches = findBestMatchForSuggestion(
unsortedNumbers , '9129370');
if (bestMatches.length != 0) {
$('.suggestion-failed').html('No Range 2').show(); return;};
$('.suggestion-failed').html('Success').show();return;});
但是当我使用vba代码时,没有responseText !!
but when i use vba code, there is no responseText!!
Set MyRequest = CreateObject("MSXML2.XMLHTTP.6.0")
MyRequest.Open "GET", "http://sim.mci.ir/get-free-nums", False
MyRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
MyRequest.Send "{range: 9129370}"
我该怎么办?是不是直接在vba中执行此操作?
what shoud i do? is it pussible to do this in vba directly?
推荐答案
.ajax({url:' http://sim.mci.ir/get-free-nums',data:{range:range},type:' GET'})。done(函数(响应){
response = JSON.parse(response);
var unsortedNumbers = response.numbers;
if (response.status!= ' OK'){
.ajax({url: 'http://sim.mci.ir/get-free-nums',data: {range: range},type: 'GET'}).done(function (response) { response = JSON.parse(response); var unsortedNumbers = response.numbers; if (response.status != 'OK') {
(' 。 suggestion-failed')。html(' No Service')。show();
return ;};
if (unsortedNumbers.length == 0 ){
('.suggestion-failed').html('No Service').show(); return;}; if (unsortedNumbers.length == 0) {
(' 。suggestion-failed')。html(' No Range' )。节目(); return ;};
var bestMatches = findBestMatchForSuggestion(
unsortedNumbers,' 9129370');
if (bestMatches.length!= 0 ){
('.suggestion-failed').html('No Range').show(); return;}; var bestMatches = findBestMatchForSuggestion( unsortedNumbers , '9129370'); if (bestMatches.length != 0) {
这篇关于如何在Excel Vba中获取Http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!