Adapted code to cURL.