Windows批处理文件中的CURL [英] CURL inside windows batch file

查看:1087
本文介绍了Windows批处理文件中的CURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows批处理文件中使用CURL.我需要捕获变量内的响应,但是很挣扎.我尝试了几种语法,如果尝试使用curl_setopt,则会收到有关未定义环境变量的错误.回到我开始的基础...

I'm trying to use CURL inside a windows batch file. I need to capture the response inside a variable but am struggling. I have tried several syntaxes and if I attempt to use curl_setopt I get an error about the Environment variable not being defined. Going back to basics I started with ...

set response = curl http://www.google.co.uk

任何帮助将不胜感激.

推荐答案

@echo off
setlocal disableDelayedExpansion
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%

setlocal enableDelayedExpansion
set "response="
for /f "delims=" %%r in ('curl http://www.google.co.uk 2^>^&1') do (
  set response=!response!%NL%%%r 
)
echo %response%
endlocal
endlocal

这篇关于Windows批处理文件中的CURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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