This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1,35 @@
((function(url,callback,method,post,headers){//headers is an object like this {Connection:"keep-alive"}
function createXMLHttpRequest() {
if (typeof XMLHttpRequest != "undefined") {
return new XMLHttpRequest();
} else if (typeof window.ActiveXObject != "undefined") {
try {
return new ActiveXObject("Msxml2.XMLHTTP.4.0");
} catch (e) {
try {
return new ActiveXObject("MSXML2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return null;
}
}
}
}
}
function looProp(object,callback){
var a;
for(a in object){
if(object.hasOwnProperty(a))callback.call(object,a,object[a]);
}
}
method=method||"GET";
var xhr=createXMLHttpRequest();
if(xhr){
xhr.open(method,url,true);
looProp(headers,function(a,b){xhr.setRequestHeader(a,b)})
xhr.onreadystatechange=function(){if(xhr.readyState==xhr.DONE){callback(xhr)}};
xhr.send(post);
return xhr;}else{return null;}
})('http://rosettacode.org',function(xhr){console.log(xhr.responseText)}))

View file

@ -0,0 +1,3 @@
readurl(url) = open(readlines, download(url))
readurl("http://rosettacode.org/index.html")

View file

@ -0,0 +1,17 @@
using System;
using System.Console;
using System.Net;
using System.IO;
module HTTP
{
Main() : void
{
def wc = WebClient();
def myStream = wc.OpenRead("http://rosettacode.org");
def sr = StreamReader(myStream);
WriteLine(sr.ReadToEnd());
myStream.Close()
}
}

View file

@ -1,14 +1,11 @@
use Net;
use Structure;
use HTTP;
use Collection;
bundle Default {
class HttpTest {
function : Main(args : String[]) ~ Nil {
client := HttpClient->New("http://rosettacode.org", 80);
lines := client->Get();
each(i : lines) {
lines->GetValue(i)->As(String)->PrintLine();
};
}
class HttpTest {
function : Main(args : String[]) ~ Nil {
lines := HttpClient->New()->Get("http://rosettacode.org");
each(i : lines) {
lines->Get(i)->As(String)->PrintLine();
};
}
}

View file

@ -1,12 +1,7 @@
import scala.io._
import scala.io.Source
object HttpTest {
def main(args: Array[String]): Unit = {
//if you are behind a firewall you can configure your proxy
System.setProperty("http.proxySet", "true")
System.setProperty("http.proxyHost", "0.0.0.0")
System.setProperty("http.proxyPort", "8080")
Source.fromURL("http://www.rosettacode.org").getLines.foreach(println)
}
object HttpTest extends App {
System.setProperty("http.agent", "*")
Source.fromURL("http://www.rosettacode.org").getLines.foreach(println)
}