在vba中创建的POST请求不会返回任何结果 [英] POST request created in vba brings back nothing as result

查看:464
本文介绍了在vba中创建的POST请求不会返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用POST请求在vba中编写了一个非常小的脚本.但是,当我运行它时,除了空白消息外,我什么都没有得到.我尝试相应地填写request参数.也许,我不知道应该在参数中包含哪个.我正在处理的页面的右侧面板中包含几张图像.单击图像后,我在这里谈论的请求将发送到服务器,并带回结果,并在其下显示有关其样式的新信息.我的目标是解析与每个图像相关的所有样式.无论如何,我试图附上所有必要的东西以找出我所缺少的东西.预先感谢.

I've written a very tiny script in vba using POST request. However, when I run it, I get nothing as result except for a blank message. I've tried to fill in the request parameter accordingly. Perhaps, I can't notice which should be included in the parameter. The page I'm dealing with contains several images in it's right panel. When an image is clicked the request about which i'm talking here is sent to the server and brings back the result and displays new information concerning its' flavor under it. My goal is to parse all the flavors connected to each images. Anyways, I'm trying to attach all the things necessary to find out what i'm missing. Thanks in advance.

这是我从chrome开发人员工具中准备的POST请求: " https://www.dropbox.com/s/zjn0ahixhu58miq/RequestStatus .txt?dl = 0 "

This is what I got from chrome developer tools to prepare the POST request: "https://www.dropbox.com/s/zjn0ahixhu58miq/RequestStatus.txt?dl=0"

这是我要尝试的:

Sub PostReq()

    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim ArgumentStr As String

    ArgumentStr = "opt=flavor&opt1=207&opt2=47&ip=105"
    With http
        .Open "POST", "https://www.optigura.com/product/ajax/details.php", False
        .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
        .setRequestHeader "Accept", "application/json, text/javascript, */*; q=0.01"
        .send ArgumentStr
        html.body.innerHTML = .responseText
    End With

    MsgBox http.responseText

End Sub

这是指向该网页的原始链接:

This is the original link to the webpage:

" https://www.optigura.com/uk /product/gold-standard-100-whey/"

推荐答案

最后,我做到了.要接收所需的响应,必须先发送一个GET请求,然后使用来自该get请求的响应再次发送一个POST请求.这是工作的:

Finally, I've made it. To receive the required response it is necessary to send a GET request first then again send a POST request using the response from that get request. Here is the working one:

Sub httpPost()

    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim ArgumentStr As String

    ArgumentStr = "opt=flavor&opt1=207&opt2=47&ip=105"

    With http
        .Open "GET", "https://www.optigura.com/uk/product/gold-standard-100-whey/", False
        .send
    End With

    With http
        .Open "POST", "https://www.optigura.com/product/ajax/details.php", False
        .setRequestHeader "X-Requested-With", "XMLHttpRequest"
        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
        .setRequestHeader "Accept", "application/json, text/javascript, */*; q=0.01"
        .send ArgumentStr
        html.body.innerHTML = .responseText
    End With

    MsgBox http.responseText

End Sub

这篇关于在vba中创建的POST请求不会返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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