Download given url to string
@param  {String}  url
@return {Promise}
421636
function downloadString(url, {userAgent}) {
	let deferred  = Q.defer()
	let startTime = Date.now()
	let data = ''
	request({
		method: 'GET',
		url: url,
		headers: {
			'User-Agent': userAgent
		}
	}, function(error, response, body) {
		if(error) {
			deferred.reject(new Error(error))
			return;
		}
		deferred.resolve({
			time: Date.now() - startTime,
			result: body,
			statusCode: response.statusCode
		})
	})
	return deferred.promise
}
871980
def download_file(url):
    
    response = requests.get(url)
    if response.status_code is not 200:
        return None
    return response.text
440150
def downloadFileFromUrl(self, url):
		""""""
		fullurl = self.baseUrl + url
		try:
			urlobj = urllib2.urlopen(fullurl)
			contents = urlobj.read()
		except urllib2.HTTPError, e:
			self.printd("HTTP error:", e.code, url)
			return None
		except urllib2.URLError, e:
			self.printd("URL error:", e.code, url)
			return None
		self.printd("Fetched '%s' (size %d bytes)" % (fullurl, len(contents)))
		return contents
972716
function(url, dest, callback, count) {
    if (isNaN(count)) {
      count = 10;
    }

    if (this.cache[url]) {
      return fs.writeFile(dest, this.cache[url], callback);
    }

    fs.exists(dest, function(exists) {
      if (exists) {
        // No need to download :).
        return callback && callback();
      }

      var stream = fs.createWriteStream(dest);
      debug('GET ' + url);
      var protocol = this._getProtocol(url);
      protocol.get(url, function(res) {
        if (res.statusCode !== 200) {
          debug('Bad status ' + res.statusCode + ' for ' + url + '... ' +
                'will try ' + count + ' more times');
          if (count === 0) {
            return callback && callback(
              new Error('Bad status ' + res.statusCode + ' for ' + url));
          }

          return Download.inst.downloadToDisk(url, dest, callback, count - 1);
        }

        res.pipe(stream);
        stream.on('finish', callback);
      });
    }.bind(this));
  }
121883
function downloader(url, saveAtPath, callback) {
  // Handle the parameter errors
  if (!url || !saveAtPath) {
    return callback(new Error("You need to provide the URL and the location to save the file!"));
  }
  if (url && typeof url !== "string") {
    return callback(new Error("The parameter 'url' must be a string"));
  }
  if (saveAtPath && typeof saveAtPath !== "string") {
    return callback(new Error("The parameter 'saveAtPath' must be a string"));
  }
  if (callback && typeof callback !== "function") {
    throw new Error("The callback provided must be a function");
  }

  var httpClient = url.indexOf("https://") === 0 ? https : http;

  // The directory to save the file.
  var dirToSave = path.dirname(saveAtPath);

  // Verify if the directory to save exists before downloading.
  fs.stat(dirToSave, function gettingStats(err) {
    if (err) {
      return callback(new Error("The path '" + dirToSave + "' does NOT exist!"));
    }

    var req = httpClient.get(url, function requestHandler(res) {
      if (res.statusCode === 404) {
        return callback(new Error("The resource at the given URL " + url + " does NOT exist"));
      }

      var chunks = [];

      res.on("data", function(chunk) {
        chunks.push(chunk);
      });

      res.on("end", function() {
        var buffer = Buffer.concat(chunks);

        // Finished downloading and getting the buffer to be saved.
        fs.writeFile(saveAtPath, buffer, function(err) {
          if (err) {
            var error = new Error("Error while saving image: " + err.message);
            if (err.code === "EISDIR") {
              error = new Error("Cannot save the url " + url + " as a directory " + saveAtPath);
            }
            callback(error);
          }

          fs.stat(saveAtPath, function(err, stat) {
            if (err) {
              callback(new Error("Error while getting image stats: " + err.message));
            }

            // Creating the response object.
            var response = {
              downloaded: true,
              filePath: saveAtPath,
              size: stat.size
            };

            // The request to the URL was successful and the file was saved.
            callback(null, response);
          });
        });
      });

    });

    // Handle errors during the request.
    req.on("error", function(error) {
      if (error) {
        if (error.code === "ENOTFOUND") {
          return callback(new Error("There's no internet connectivity to " + url));

        } else {
          var unknownError = new Error("Unknown error to save " + url + " as " + saveAtPath);
          unknownError.stack = error.stack;
          return callback(unknownError);
        }
      }
    });
  });
}
539867
function httpRequest(url) {
    var deferred = Q.defer();
    request(url, function(err, response, body) {
      if (err) {
        deferred.reject(new Error(err));
      } else if (!err && response.statusCode !== 200) {
        deferred.reject(new Error(response.statusCode));
      } else {
        deferred.resolve(body);
      }
    });
    return deferred.promise;
  }
1224361
function saveUrlToFile(url, filePath) {
  return new Promise((resolve, reject) => {
    const outFile = fs.createWriteStream(filePath);
    const protocol = url.startsWith('https') ? https : http;
    protocol.get(url, (response) => {
      response.pipe(outFile);
      response.on('end', () => resolve(filePath));
      response.on('error', (err) => {
        // outFile.destroy();
        // fs.unlinkSync(filePath);
        reject(err);
      });
    })
      .on('error', (err) => {
        reject(err);
      });
  });
}
1345297
function httpRequestPromise(method, urlObject) {
  if (method !== 'GET' && method !== 'HEAD') {
    return Promise.reject(new Error('We only support GET or HEAD requests'));
  }

  return new Promise(function (resolve, reject) {
    var httpsRequestOptions = {
      host: urlObject.host,
      method: method,
      path: urlObject.path
    };

    var req = https.request(httpsRequestOptions, function (res) {
      if (res.statusCode !== 200) {
        reject(new Error('Did not get 200 for ' + urlObject.href +
          ', instead got ' + res.statusCode));
        return;
      }

      resolve(res);
    })
    .on('error', function (e) {
      reject(new Error('Got error on ' + urlObject.href + ' - ' + e));
    });

    req.end();
  });
}
1363338
function downloadFile(url, outputPath) {
	const dir = path.dirname(outputPath);
	if (!fs.existsSync(dir)) {
		fs.mkdirSync(dir);
	}
	return new Promise((resolve, reject) => {
		const file = fs.createWriteStream(outputPath);
		const sendReq = request.get(url);
		sendReq.pipe(file);

		sendReq
		.on("response", (response) => {
			if (response.statusCode !== 200) {
				fs.unlink(outputPath);
				const error = new Error("Response status code was " + response.statusCode + ".");
				console.trace(error);
				reject(error);
			}
		})
		.on("error", (error) => {
			fs.unlink(outputPath);
			console.trace(error);
			reject(error);
		});

		file
		.on("finish", () => {
			file.close(() => {
				resolve();
			});
		})
		.on("error", (error) => {
			fs.unlink(outputPath);
			console.trace(error);
			reject(error);
		});
	});
}
44205
private InputStreamReader downloadUrl(String urlString) throws IOException {
        URL url = new URL(urlString);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        // Starts the query
        conn.connect();

        return new InputStreamReader(conn.getInputStream(), "UTF-8");

    }
787720
def fget(url, **options)
      uri = _assert_uri(url)
      Responses::ResponsePromise.new { get(uri, options) }
    end
830615
function (url) {
        var self = this;
        this.searching = true;
        this.loadingError = false;
        return $http.get(url)
          .success(function (res) {
            self.searching = false;
            return res.data;
          })
          .error(function () {
            self.searching = false;
            self.loadingError = true;
            return false;
          });
      }
918089
function download(url, dest, cb) {
  var reportError = function(err) {
    cb(['Cannot download "', url, '": ',
      typeof err.message === 'string' ? err.message : err].join(''));
  };
  var successful = function(response) {
    return response.statusCode >= 200 && response.statusCode < 300;
  };

  applyProxy({ rejectUnauthorized: false }, function(options) {
    options.headers = {
      'User-Agent': [
        'node/', process.version, ' ',
        'node-sass-installer/', pkg.version
      ].join('')
    };
    try {
      request(url, options, function(err, response) {
        if (err) {
          reportError(err);
        } else if (!successful(response)) {
            reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
        } else {
            cb();
        }
      }).on('response', function(response) {
          if (successful(response)) {
            response.pipe(fs.createWriteStream(dest));
          }
      });
    } catch (err) {
      cb(err);
    }
  });
}
1282135
function request (url, options) {
  options = Object.assign({}, defaultOptions, options)
  let savedContent
  let savedResponse

  return new Promise((resolve, reject) => {
    fetch(url, options)
      .then(handleResponse)
      .then(handleBody)
      .catch(handleError)

    function handleResponse (response) {
      // Save the response for checking the status later
      savedResponse = response

      // Decode the response body
      switch (options.type) {
        case 'response':
          return response
        case 'json':
          return response.json()
        default:
          return response.text()
      }
    }

    function handleBody (content) {
      // Bubble an error if the response status is not okay
      if (savedResponse && savedResponse.status >= 400) {
        savedContent = content
        throw new Error(`Response status indicates error`)
      }

      // All is well!
      resolve(content)
    }

    function handleError (err) {
      // Overwrite potential decoding errors when the actual problem was the response
      if (savedResponse && savedResponse.status >= 400) {
        err = new Error(`Status ${savedResponse.status}`)
      }

      // Enrich the error message with the response and the content
      let error = new Error(err.message)
      error.response = savedResponse
      error.content = savedContent
      reject(error)
    }
  })
}
1270142
function(url) {
		return new Promise(function (resolve) {
			self.roptions.url = url;
			request(self.roptions, function (err, response, body) {
				if (!err && response.statusCode === 200) {
					var $ = cheerio.load(body);

					// no results
					if (!$('.result').length) {
						return resolve(result);
					}
					
					$('.result').each(function() {
						var href = $(this).find('a').attr('href');
						if(href.toString().indexOf("http") !== 0) {
							result.push(base + href); 							
						} else {
							result.push(href); 							
						}
					});

					if (num && result.length > num) {
						return resolve(result.slice(0,num));
					}

					// search for current page and select next one
					var page = $('#nextPage').attr('href');
					if (page) {
						resolve(nextPage(base + page));
					}
					else {
						resolve(result);
					}
				} else {
					resolve(result)
				}
			});
		});
	}
708474
function download(target, dest, opts, fn) {
	if (typeof opts === 'function') {
		fn = opts;
		opts = null;
	}
	opts = opts || {};
	let clone = opts.clone || false;

	const repo = normalize(target);
	let url = getUrl(repo, clone);
	if (url && typeof url === 'object' && url.url) {
		if (typeof url.clone === 'boolean') {
			clone = url.clone;
		}
		url = url.url;
	}

	return PromiseA.try(() => {
		if (clone) {
			const checkout = repo.checkout && repo.checkout !== 'master' ? repo.checkout : null;
			debug('Cloning from:', url, checkout ? '#' + checkout : '');
			return PromiseA.fromCallback(cb => gitclone(url, dest, {checkout}, cb)).then(() => rm(dest + '/.git'));
		} else {
			debug('Downloading from:', url);
			return PromiseA.resolve(downloadUrl(url, dest, {extract: true, strip: 1, mode: '666', headers: {accept: 'application/zip'}}));
		}
	}).asCallback(fn);
}
777497
function promisedRequest(url) {
	var taskId = this[0], req = Object.create(this[1]);
	var method = req.method || 'get';

	if ('args' in req) {
		req.url = url + taskId + find_separator(url) + req.args
	}
	else {
		req.url = url + taskId
	}

	return new Promise(function(resolve, reject) {
		return request[method](req, function(err, response, body) {
			return err ? reject({error: err, headers: response && response.headers})
				: resolve({body: body, headers: response.headers});
		});
	});
}