Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

httpwebrequest - http web request from batch file

I need to execute a http web request from Plesk's Task Scheduler (using shared hosting on Windows/ASP.NET; no Powershell, whatsoever). Thought about using a batch file for this.

Is there an easy way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Without external binaries - only the built-in windows capabilities -> https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/winhttpjs.bat

This is jscript/.bat hybrid and can be called like simple bat. Example usage (I've used http://requestb.in/ for test purposes):

  call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt
   
  call winhttpjs.bat "http://requestb.in/xxxxxx" -method GET -header hdrs.txt -reportfile reportfile3.txt -saveTo c:somezip.zip 

  call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt -saveTo responsefile2 -ua "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"  -body-file some.json

Header files format should look like (if passed with -header command argument):

Header-1: Value-1
ExampleHeader: Value2

Does not support multi-part requests (though I'm planning to add such a feature (some day))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...