【问题标题】:CURL command to translate in Powershell or VBS在 Powershell 或 VBS 中翻译的 CURL 命令
【发布时间】:2018-05-09 18:12:51
【问题描述】:

我在 CURL 中有一个返回数据的命令。我尝试将其转换为 PowerShell 或 VBS,但我无法获取任何数据并且我的代码中没有错误消息。

以下是我的 CURL 命令:

$Data = curl "http://www.boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/derives/search/turbos?" -H "X-Requested-With: XMLHttpRequest" -H "X-Brs-Xhr-Request: true" --data "class=Boursorama_Block_Bourse_Derives_Search_Turbos" --compressed

以下是我的 Powershell 命令:

$hash =@{
"class" = "Boursorama_Block_Bourse_Derives_Search_Turbos"
}

$JSON = $hash | ConvertTo-Json
$R = Invoke-WebRequest -Method Post -URI "http://www.boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/derives/search/turbos?" -Headers @{"X-Brs-Xhr-Request"="true"} -Body $JSON -ContentType “application/json”
$R.Content

以下是我的 VBS 命令:

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
strJSONToSend = "{""class"": ""Boursorama_Block_Bourse_Derives_Search_Turbos""}"
xmlhttp.open "POST","http://www.boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/derives/search/turbos?",False
xmlhttp.setRequestHeader "X-Brs-Xhr-Request", "true"
xmlhttp.send strJSONToSend
xmlhttp.responseText

我有最后一个问题,我正在尝试发送参数“page”,但结果相同,但页码不同。

以下是 PowerShell 命令:

$Data = Invoke-WebRequest -Method Post -URI "http://www.boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/derives/search/turbos?page=2" -Headers @{"X-Brs-Xhr-Request"="true";"X-Requested-With" = "XMLHttpRequest"} -body @{"class"="Boursorama_Block_Bourse_Derives_Search_Turbos";"parameters[page]"="2"}

我不知道参数必须在URL中还是在正文中发送。

【问题讨论】:

    标签: json powershell curl


    【解决方案1】:

    向阿德里安致敬。

    使用 PowerShell 你可以测试类似的东西:

    Invoke-WebRequest -Method Post -URI "http://www.boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/derives/search/turbos?" -Headers @{"X-Brs-Xhr-Request"="true";"X-Requested-With" = "XMLHttpRequest"}   -body "class=Boursorama_Block_Bourse_Derives_Search_Turbos"
    

    我收到了一个答案,但我不知道是不是您要找的那个。

    这是页面。

    Invoke-WebRequest -Method Post -URI "http://www.boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/derives/search/turbos?" -Headers @{"X-Brs-Xhr-Request"="true";"X-Requested-With" = "XMLHttpRequest"}   -body "parameters[page]=2&class=Boursorama_Block_Bourse_Derives_Search_Turbos"
    

    【讨论】:

    • 谢谢 beaucoup JP。是的,这就是我正在寻找的结果。我有最后一个问题,我正在尝试发送参数“page”,但结果相同,但页码不同。
    • 如何用Curl发送页面参数。不是用网址吗?
    • 它在 URL 和参数中,以下是请求: curl "boursorama.com/ajax/ui/refresh.phtml/boursorama/block/bourse/…" --data "parameters^[page^]=2^&class=Boursorama_Block_Bourse_Derives_Search_Turbos" --compressed
    • 谢谢您,我认为您的请求和语法是正确的,但是如果 page = 2 或 50 则响应相同,我不知道为什么。
    • JPBlanc 已经回答了这个问题,对于剩下的问题,我会再问一个问题,并提供更多详细信息。
    猜你喜欢
    • 2017-06-10
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多