Batch programming check http call status 1

Batch programming check http call status

SET SOME_URL="https://my/api/to/get/something"
SET HTTP=
for /f %%a in ( 'curl -k -s -o NUL -w "%%{http_code}" "%SOME_URL%"' ) do set HTTP=%%a
if "%HTTP%" == "200" (
  echo "SUCCESS."
  REM Do rest of you stuff here
) else (
  echo "FAIL."
  REM Do any kind of cleanups
  exit /b
)

Here is what the above code is Doing:
1. Set the URL to be called
2. Set the HTTP variable to empty
3. Call the curl command and get the HTTP response code
4. If the HTTP response code is 200, then do the rest of your stuff
5. If the HTTP response code is not 200, then do any kind of cleanups and exit

Similar Posts