【问题标题】:POST CURL with request header and payload in vbscript在 vbscript 中使用请求标头和有效负载发布 CURL
【发布时间】:2016-07-06 06:53:22
【问题描述】:

我在 parse.com 上使用云代码创建了一个项目。

现在我想创建一个 VBScript 来调用 CURL,如下所示。

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "Content-Type: application/json" \
  -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
  http://localhost:1337/parse/classes/GameScore

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "Content-Type: application/json" \
  -d '{}' \
  http://localhost:1337/parse/functions/hello

在javascript中我们可以通过以下代码实现。

Parse.initialize('myAppId','unused');
Parse.serverURL = 'https://whatever.herokuapp.com';

var obj = new Parse.Object('GameScore');
obj.set('score',1337);
obj.save().then(function(obj) {
  console.log(obj.toJSON());
  var query = new Parse.Query('GameScore');
  query.get(obj.id).then(function(objAgain) {
    console.log(objAgain.toJSON());
  }, function(err) {console.log(err); });
}, function(err) { console.log(err); });

如何使用 VBScript 实现 .vbs 文件?

【问题讨论】:

标签: curl parse-platform vbscript


【解决方案1】:

请尝试以下代码。

strRequest="{""eventId"":""TOaDAOqueV""}"
EndPointLink = "http://X.X.X.X:1337/parse/functions/method"

dim http
set http=createObject("Microsoft.XMLHTTP")
http.open "POST",EndPointLink,false
http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "X-Parse-Application-Id","XXXXXXXXXXXXXXXXXXXXX"

msgbox "REQUEST : " & strRequest
http.send strRequest

If http.Status = 200 Then
    msgbox "RESPONSE : " & http.responseText
    responseText=http.responseText
else
    msgbox "ERRCODE : " & http.status
End If

答案部分来自HTTP GET in VBS@rajkumar-joshua-m

【讨论】:

  • 嗨,Kaludi,我编辑的代码中有一些语法错误。但是您的解决方案对我有用。非常感谢您的解决方案:)。
  • 请记住,仅检查 200 的 HTTP 状态意味着 HTTP 203 Created 不会被归类为成功,理想情况下,您应该检查是否收到任何 2xx 响应,因为它们都是成功代码。像Left(http.Status, 1) = 2 这样的东西就足够了。
  • 当你使用别人的代码时,请注明出处——见HTTP GET in VBS(直接复制/粘贴,用相同的变量和输出稍作修改)
猜你喜欢
  • 2020-04-30
  • 2018-04-24
  • 2019-04-03
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 2018-10-14
  • 1970-01-01
相关资源
最近更新 更多