0

I have created a project on parse.com with cloud code.

Now I want to create a VBScript to call CURL as below.

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

In javascript we can achieve it by following code.

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); });

How can I achieve it using VBScript for .vbs file?

Get updates on questions and answers

1 Answer

2

Please try the following code.

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

Answer partially taken from HTTP GET in VBS by @rajkumar-joshua-m

  • Hi Kaludi, there was some syntax error in your code I have edited. But your solution just worked for me. Thanks a lot for the solution :).  Jul 6, 2016 at 7:35
  • Bear in mind that just checking for HTTP status of 200 means HTTP 203 Created would not be classed as a success, ideally you should check you receive any 2xx response as they are all success codes. Something like Left(http.Status, 1) = 2 should be enough.  Jul 6, 2016 at 8:30 
  • When you use someone else's code please provide attribution - See HTTP GET in VBS (direct copy / paste slightly modified with the same variables and output).  Jul 6, 2016 at 9:22 

Your Answer


来自  https://stackoverflow.com/questions/38217863/post-curl-with-request-header-and-payload-in-vbscript