This language bar is your friend. Select your favorite languages!

Idiom #101 Load from HTTP GET request into a string

Make an HTTP request with method GET to URL u, then store the body of the response in string s.

(def s (slurp u))
using System.Net.Http;
var client = new HttpClient();
s = await client.GetStringAsync(u);
import std.conv;
string s =!string;
import "io/ioutil"
import "net/http"
res, err := http.Get(u)
if err != nil {
	return err
buffer, err := ioutil.ReadAll(res.Body)
if err != nil {
	return err
s := string(buffer)
String s = u.text
<script src=""></script>
$.get(u, function(data){
  s = data;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		s = xmlHttp.responseText;
}"GET", u, true);
$s = file_get_contents($u);
uses fphttpclient;
with TFPHTTPClient.Create(nil) do try
  s := get(u);
use HTTP::Tiny qw();
my $s = HTTP::Tiny->new->get($u)->{content};
import urllib.request
with urllib.request.urlopen(u) as f:
    s =
require 'net/http'
u = URI("")
s = Net::HTTP.get_response(u).body
extern crate reqwest;
use reqwest::Client;
let client = Client::new();
let s = client.get(u).send().and_then(|res| res.text())?;
ureq = "1.0"
let s = ureq::get(u).call().into_string()?;
val s ="\n")

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Related idioms