A
A
AlexeyMoshkin2016-06-23 09:58:24
cmd/bat
AlexeyMoshkin, 2016-06-23 09:58:24

How to extract link from curl response in bat file?

I make a request via curl from a bat file. From the request response body

{
   "href":"https://uploader9m.disk.yandex.net:443/upload-target/20160623T092605.135.utd.eb5dbfed7bwwb6imitb6xku41-k9m.5744252",
   "method":"PUT",
   "templated":false
}

I want to get the value of "href", i.e. the string
"https://uploader9m.disk.yandex.net:443/upload-target/20160623T092605.135.utd.eb5dbfed7bwwb6imitb6xku41-k9m.5744252"

How can this be done simply and correctly?
Is there an option to have curl immediately return the "href" value?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexeyMoshkin, 2016-06-23
@AlexeyMoshkin

I used the jq console utility , as a result, getting href from the response for my case looks like this:

for /f "delims=" %%i in ('curl -H %H% %link_to_get_upload%') do set response=%%i
echo %response% | C:\jq.exe ".href" > %file%
set /p upload_url= < %file%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question