mardi 16 février 2016

Batch file gets number of bytes returned from a web request and use in a conditional statement

I need to make a POST request to get data from an API and then based on the number of bytes returned decide whether or not to save the data. I'm doing this because I don't want to overwrite the current data file if the response returns an empty data set. I figured the best way to check for this would be to make sure the response was at least a certain number of bytes.

Here I am making a POST request and saving the response data to the file data.json. I also need to wrap the file in a JSONP function call "getData()".

@echo off
(
    echo|set /p=getData^(
    curl --insecure -X POST "http://ift.tt/217rl1H" -H  "content-type: application/json" -d @query.body
    echo|set /p=^) 
) > data.json

Aucun commentaire:

Enregistrer un commentaire