HTTP: Difference between revisions

From Rosetta Code
Content added Content deleted
(Testing)
No edit summary
Line 1: Line 1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
{{task|Programming environment operations}}[[Category:Networking and Web Interaction]]
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="MediaWiki 1.13.3" />
<meta name="robots" content="noindex,nofollow" />
<meta name="keywords" content="HTTP" />
<link rel="alternate" type="application/rss+xml" title="Rosetta Code: New tasks - RSS 2.0" href="/w/index.php?title=Special:NewsChannel&amp;format=rss20" />
<link rel="alternate" type="application/atom+xml" title="Rosetta Code: New tasks - Atom 1.0" href="/w/index.php?title=Special:NewsChannel&amp;format=atom10" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Rosetta Code (en)" />
<link title="Creative Commons" type="application/rdf+xml" href="/w/index.php?title=HTTP&amp;action=creativecommons" rel="meta" />
<link rel="copyright" href="http://www.gnu.org/copyleft/fdl.html" />
<link rel="alternate" type="application/rss+xml" title="Rosetta Code RSS Feed" href="http://www.rosettacode.org/w/index.php?title=Special:RecentChanges&amp;feed=rss" />
<link rel="alternate" type="application/atom+xml" title="Rosetta Code Atom Feed" href="http://www.rosettacode.org/w/index.php?title=Special:RecentChanges&amp;feed=atom" />
<title>HTTP - Rosetta Code</title>
<style type="text/css" media="screen, projection">/*<![CDATA[*/
@import "/w/skins/common/shared.css?164";
@import "/w/skins/monobook/main.css?164";
/*]]>*/</style>
<link rel="stylesheet" type="text/css" media="print" href="/w/skins/common/commonPrint.css?164" />
<!--[if lt IE 5.5000]><style type="text/css">@import "/w/skins/monobook/IE50Fixes.css?164";</style><![endif]-->
<!--[if IE 5.5000]><style type="text/css">@import "/w/skins/monobook/IE55Fixes.css?164";</style><![endif]-->
<!--[if IE 6]><style type="text/css">@import "/w/skins/monobook/IE60Fixes.css?164";</style><![endif]-->
<!--[if IE 7]><style type="text/css">@import "/w/skins/monobook/IE70Fixes.css?164";</style><![endif]-->
<!--[if lt IE 7]><script type="text/javascript" src="/w/skins/common/IEFixes.js?164"></script>
<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
<script type= "text/javascript">/*<![CDATA[*/
var skin = "monobook";
var stylepath = "/w/skins";
var wgArticlePath = "/wiki/$1";
var wgScriptPath = "/w";
var wgScript = "/w/index.php";
var wgVariantArticlePath = false;
var wgActionPaths = [];
var wgServer = "http://www.rosettacode.org";
var wgCanonicalNamespace = "";
var wgCanonicalSpecialPageName = false;
var wgNamespaceNumber = 0;
var wgPageName = "HTTP";
var wgTitle = "HTTP";
var wgAction = "view";
var wgArticleId = 0;
var wgIsArticle = true;
var wgUserName = null;
var wgUserGroups = null;
var wgUserLanguage = "en";
var wgContentLanguage = "en";
var wgBreakFrames = false;
var wgCurRevisionId = false;
var wgVersion = "1.13.3";
var wgEnableAPI = true;
var wgEnableWriteAPI = true;
var wgRestrictionEdit = [];
var wgRestrictionMove = [];
/*]]>*/</script>
<script type="text/javascript" src="/w/skins/common/wikibits.js?164"><!-- wikibits js --></script>
<script type="text/javascript" src="/w/index.php?title=-&amp;action=raw&amp;gen=js&amp;useskin=monobook"><!-- site js --></script>
<style type="text/css">/*<![CDATA[*/
@import "/w/index.php?title=MediaWiki:Common.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";
@import "/w/index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";
@import "/w/index.php?title=-&action=raw&gen=css&maxage=18000&useskin=monobook";
/*]]>*/</style>
<!-- Head Scripts -->
<script type="text/javascript" src="/w/skins/common/ajax.js?164"></script>
</head>
<body class="mediawiki ns-0 ltr page-HTTP">
<div id="globalWrapper">
<div id="column-content">
<div id="content">
<a name="top" id="top"></a>
<h1 class="firstHeading">HTTP</h1>
<div id="bodyContent">
<h3 id="siteSub">From Rosetta Code</h3>
<div id="contentSub"></div>
<div id="jump-to-nav">Jump to: <a href="#column-one">navigation</a>, <a href="#searchInput">search</a></div> <!-- start content -->
<div class="noarticletext">
<p>There is currently no text in this page, you can <a href="/wiki/Special:Search/HTTP" title="Special:Search/HTTP">search for this page title</a> in other pages or <a href="http://www.rosettacode.org/w/index.php?title=HTTP&amp;action=edit" class="external text" title="http://www.rosettacode.org/w/index.php?title=HTTP&amp;action=edit" rel="nofollow">edit this page</a>.
</p>
</div>


<!--
Print a URL's content (source code) to the console.
NewPP limit report

Preprocessor node count: 6/1000000
=={{header|ActionScript}}==
Post-expand include size: 69/2097152 bytes
<actionscript>package
Template argument size: 0/2097152 bytes
{
Expensive parser function count: 0/100
import flash.display.Sprite;
-->
import flash.events.Event;
<div class="printfooter">
import flash.net.*;
Retrieved from "<a href="http://www.rosettacode.org/wiki/HTTP">http://www.rosettacode.org/wiki/HTTP</a>"</div>

<!-- end content -->
public class RequestExample extends Sprite
<div class="visualClear"></div>
{
</div>
public function RequestExample()
</div>
{
</div>
var loader:URLLoader = new URLLoader();
<div id="column-one">
loader.addEventListener(Event.COMPLETE, loadComplete);
<div id="p-cactions" class="portlet">
loader.load(new URLRequest("http://www.rosettacode.org"));
<h5>Views</h5>
}
<div class="pBody">
<ul>
<li id="ca-nstab-main" class="selected new"><a href="/w/index.php?title=HTTP&amp;action=edit" title="View the content page [c]" accesskey="c">Page</a></li>
<li id="ca-talk" class="new"><a href="/w/index.php?title=Talk:HTTP&amp;action=edit" title="Discussion about the content page [t]" accesskey="t">Discussion</a></li>
<li id="ca-edit"><a href="/w/index.php?title=HTTP&amp;action=edit" title="You can edit this page.&#10;Please use the preview button before saving. [e]" accesskey="e">Create</a></li>
</ul>
</div>
</div>
<div class="portlet" id="p-personal">
<h5>Personal tools</h5>
<div class="pBody">
<ul>
<li id="pt-login"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=HTTP" title="You are encouraged to log in, it is not mandatory however. [o]" accesskey="o">Log in / create account</a></li>
</ul>
</div>
</div>
<div class="portlet" id="p-logo">
<a style="background-image: url(/w/title.png);" href="/wiki/Main_Page" title="Visit the Main Page [z]" accesskey="z"></a>
</div>
<script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
<div class='portlet' id='p-Browse'>
<h5>Browse</h5>
<div class='pBody'>
<ul>
<li id="n-mainpage"><a href="/wiki/Main_Page" title="Visit the Main Page [z]" accesskey="z">Main Page</a></li>
<li id="n-Solutions-by-Language"><a href="/wiki/Category:Solutions_by_Programming_Language">Solutions by Language</a></li>
<li id="n-Solutions-by-Task"><a href="/wiki/Category:Solutions_by_Programming_Task">Solutions by Task</a></li>
<li id="n-Encyclopedia"><a href="/wiki/Category:Encyclopedia">Encyclopedia</a></li>
<li id="n-recentchanges"><a href="/wiki/Special:RecentChanges" title="The list of recent changes in the wiki. [r]" accesskey="r">Recent changes</a></li>
<li id="n-randompage"><a href="/wiki/Special:Random" title="Load a random page [x]" accesskey="x">Random page</a></li>
</ul>
</div>
</div>
<div class='portlet' id='p-Contribute'>
<h5>Contribute</h5>
<div class='pBody'>
<ul>
<li id="n-Contribute-Content"><a href="/wiki/Help:Contribute_Content">Contribute Content</a></li>
<li id="n-Pages-needing-attention"><a href="/wiki/Category:Maintenance">Pages needing attention</a></li>
<li id="n-Request-a-task"><a href="/wiki/Help:Request_a_new_programming_task">Request a task</a></li>
<li id="n-Request-a-language"><a href="/wiki/Help:Request_a_language_focus">Request a language</a></li>
</ul>
</div>
</div>
<div class='portlet' id='p-Community'>
<h5>Community</h5>
<div class='pBody'>
<ul>
<li id="n-Village-Pump"><a href="/wiki/Village_Pump:Home">Village Pump</a></li>
<li id="n-Blog"><a href="http://blog.rosettacode.org">Blog</a></li>
<li id="n-Similar-sites"><a href="/wiki/Help:Similar_Sites">Similar sites</a></li>
<li id="n-Internet-Relay-Chat"><a href="/wiki/Help:IRC">Internet Relay Chat</a></li>
</ul>
</div>
</div>
<div id="p-search" class="portlet">
<h5><label for="searchInput">Search</label></h5>
<div id="searchBody" class="pBody">
<form action="/wiki/Special:Search" id="searchform"><div>
<input id="searchInput" name="search" type="text" title="Search Rosetta Code [f]" accesskey="f" value="" />
<input type='submit' name="go" class="searchButton" id="searchGoButton" value="Go" />&nbsp;
<input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="Search" />
</div></form>
</div>
</div>
<div class="portlet" id="p-tb">
<h5>Toolbox</h5>
<div class="pBody">
<ul>
<li id="t-whatlinkshere"><a href="/wiki/Special:WhatLinksHere/HTTP" title="List of all wiki pages that link here [j]" accesskey="j">What links here</a></li>
<li id="t-upload"><a href="/wiki/Special:Upload" title="Upload files [u]" accesskey="u">Upload file</a></li>
<li id="t-specialpages"><a href="/wiki/Special:SpecialPages" title="List of all special pages [q]" accesskey="q">Special pages</a></li>
<li id="t-print"><a href="/w/index.php?title=HTTP&amp;printable=yes" title="Printable version of this page [p]" accesskey="p">Printable version</a></li> </ul>
</div>
</div>
</div><!-- end of the left (by default at least) column -->
<div class="visualClear"></div>
<div id="footer">
<div id="f-poweredbyico"><a href="http://www.mediawiki.org/"><img src="/w/skins/common/images/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" /></a></div>
<div id="f-copyrightico"><a href="http://www.gnu.org/copyleft/fdl.html"><img src="/w/skins/common/images/gnu-fdl.png" alt='GNU Free Documentation License 1.2' /></a></div>
<ul id="f-list">
<li id="privacy"><a href="/wiki/Rosetta_Code:Privacy_policy" title="Rosetta Code:Privacy policy">Privacy policy</a></li>
<li id="about"><a href="/wiki/Rosetta_Code:About" title="Rosetta Code:About">About Rosetta Code</a></li>
<li id="disclaimer"><a href="/wiki/Rosetta_Code:General_disclaimer" title="Rosetta Code:General disclaimer">Disclaimers</a></li>
</ul>
</div>
private function loadComplete(evt:Event):void
<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>
{
trace(evt.target.data);
}
}
}</lang>

=={{header|C}}==

{{libheader|libcurl}}

<c>#include <stdio.h>
#include <curl/curl.h>

int main()
{
CURL *curlHandle;

curlHandle = curl_easy_init();
curl_easy_setopt(curlHandle, CURLOPT_URL, "http://www.rosettacode.org");
/* the following let us specify rosettacode.org instead of
rosettacode.org/wiki/Main_Page */
curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1);
int success = curl_easy_perform(curlHandle);
curl_easy_cleanup(curlHandle);
return 0;
}</lang>

=={{header|C sharp|C#}}==

<code csharp>using System;
using System.Net;
using System.Text;

class Program
{
static void Main()
{
string url = "http://www.rosettacode.org/";
WebClient wc = new WebClient();
byte[] data = wc.DownloadData(url);
string content = Encoding.UTF8.GetString(data);
Console.WriteLine(content);
}
}</lang>

=={{header|Erlang}}==
===Synchronous===
-module(main).
-export([main/1]).
main([Url|[]]) ->
inets:start(),
case http:request(Url) of
{ok, {_V, _H, Body}} -> io:fwrite("~p~n",[Body]);
{error, Res} -> io:fwrite("~p~n", Res)
end.

===Asynchronous===

-module(main).
-export([main/1]).
main([Url|[]]) ->
inets:start(),
http:request(get, {Url, [] }, [], [{sync, false}]),
receive
{http, {_ReqId, Res}} -> io:fwrite("~p~n",[Res]);
_Any -> io:fwrite("Error: ~p~n",[_Any])
after 10000 -> io:fwrite("Timed out.~n",[])
end.

Using it
<nowiki>|escript ./req.erl http://www.rosettacode.org</nowiki>

=={{header|Icon}}==
link cfunc
procedure main(args)
get(args[1])
end
procedure get(url)
local f, host, port, path
url ? {
="http://" | ="HTTP://"
host := tab(upto(':/') | 0)
if not (=":" & (port := integer(tab(upto('/'))))) then port := 80
if pos(0) then path := "/" else path := tab(0)
}
write(host)
write(path)
f := tconnect(host, port) | stop("Unable to connect")
writes(f, "GET ", path | "/" ," HTTP/1.0\r\n\r\n")
while write(read(f))
end
Using it
<nowiki>|icon req.icn http://www.rosettacode.org</nowiki>

=={{header|Java}}==

<lang java5>import java.util.Scanner;
import java.net.URL;

public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.rosettacode.org");
Scanner sc = new Scanner(url.openStream());
while( sc.hasNext() ) System.out.println(sc.nextLine());
}
}</lang>

Apache Commons IO

<lang java5>import org.apache.commons.io.IOUtils;
import java.net.*;

public class Main {
public static void main(String[] args) throws Exception {
IOUtils.copy(new URL("http://rosettacode.org").openStream(),System.out);
}
}</lang>

=={{header|Perl}}==

<lang perl>using LWP::Simple;
print get("http://www.rosettacode.org");</lang>

=={{header|PHP}}==

<lang php>print(file_get_contents("http://www.rosettacode.org"));</lang>

=={{header|Python}}==

<lang python>import urllib
url = urllib.urlopen("http://www.rosettacode.org")
print url.read()
url.close()</lang>

<lang python>import urllib
print urllib.urlopen("http://rosettacode.org").read()</lang>

=={{header|Ruby}}==

<lang ruby>require 'open-uri'
require 'kconv'

puts open("http://rosettacode.org").read</lang>

=={{header|Tcl}}==

<lang tcl>package require http
set request [http::geturl "http://www.rosettacode.org"]
puts [http::data $request]</lang>

=={{header|UNIX Shell}}==

<lang bash>wget http://www.rosettacode.org -O tmp -o /dev/null
cat tmp
rm tmp</lang>


<!-- Set $wgGoogleAnalyticsAccount to your account # provided by Google Analytics. --></div>
<lang bash>
curl -s http://www.rosettacode.org/</lang>
<!-- Served in 0.262 secs. --><!--http://www.rosettacode.org-->
</body></html>

Revision as of 14:58, 3 February 2009

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="MediaWiki 1.13.3" /> <meta name="robots" content="noindex,nofollow" /> <meta name="keywords" content="HTTP" /> <link rel="alternate" type="application/rss+xml" title="Rosetta Code: New tasks - RSS 2.0" href="/w/index.php?title=Special:NewsChannel&format=rss20" /> <link rel="alternate" type="application/atom+xml" title="Rosetta Code: New tasks - Atom 1.0" href="/w/index.php?title=Special:NewsChannel&format=atom10" /> <link rel="shortcut icon" href="/favicon.ico" /> <link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Rosetta Code (en)" /> <link title="Creative Commons" type="application/rdf+xml" href="/w/index.php?title=HTTP&action=creativecommons" rel="meta" /> <link rel="copyright" href="http://www.gnu.org/copyleft/fdl.html" /> <link rel="alternate" type="application/rss+xml" title="Rosetta Code RSS Feed" href="http://www.rosettacode.org/w/index.php?title=Special:RecentChanges&feed=rss" /> <link rel="alternate" type="application/atom+xml" title="Rosetta Code Atom Feed" href="http://www.rosettacode.org/w/index.php?title=Special:RecentChanges&feed=atom" /> <title>HTTP - Rosetta Code</title> <style type="text/css" media="screen, projection">/*<![CDATA[*/ @import "/w/skins/common/shared.css?164"; @import "/w/skins/monobook/main.css?164"; /*]]>*/</style> <link rel="stylesheet" type="text/css" media="print" href="/w/skins/common/commonPrint.css?164" />

<script type= "text/javascript">/*<![CDATA[*/ var skin = "monobook"; var stylepath = "/w/skins"; var wgArticlePath = "/wiki/$1"; var wgScriptPath = "/w"; var wgScript = "/w/index.php"; var wgVariantArticlePath = false; var wgActionPaths = []; var wgServer = "http://www.rosettacode.org"; var wgCanonicalNamespace = ""; var wgCanonicalSpecialPageName = false; var wgNamespaceNumber = 0; var wgPageName = "HTTP"; var wgTitle = "HTTP"; var wgAction = "view"; var wgArticleId = 0; var wgIsArticle = true; var wgUserName = null; var wgUserGroups = null; var wgUserLanguage = "en"; var wgContentLanguage = "en"; var wgBreakFrames = false; var wgCurRevisionId = false; var wgVersion = "1.13.3"; var wgEnableAPI = true; var wgEnableWriteAPI = true; var wgRestrictionEdit = []; var wgRestrictionMove = []; /*]]>*/</script>

<script type="text/javascript" src="/w/skins/common/wikibits.js?164"></script> <script type="text/javascript" src="/w/index.php?title=-&action=raw&gen=js&useskin=monobook"></script> <style type="text/css">/*<![CDATA[*/ @import "/w/index.php?title=MediaWiki:Common.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000"; @import "/w/index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000"; @import "/w/index.php?title=-&action=raw&gen=css&maxage=18000&useskin=monobook"; /*]]>*/</style> <script type="text/javascript" src="/w/skins/common/ajax.js?164"></script> </head> <body class="mediawiki ns-0 ltr page-HTTP">

<a name="top" id="top"></a>

HTTP

From Rosetta Code

Jump to: <a href="#column-one">navigation</a>, <a href="#searchInput">search</a>

There is currently no text in this page, you can <a href="/wiki/Special:Search/HTTP" title="Special:Search/HTTP">search for this page title</a> in other pages or <a href="http://www.rosettacode.org/w/index.php?title=HTTP&action=edit" class="external text" title="http://www.rosettacode.org/w/index.php?title=HTTP&action=edit" rel="nofollow">edit this page</a>.

Views
  • <a href="/w/index.php?title=HTTP&action=edit" title="View the content page [c]" accesskey="c">Page</a>
  • <a href="/w/index.php?title=Talk:HTTP&action=edit" title="Discussion about the content page [t]" accesskey="t">Discussion</a>
  • <a href="/w/index.php?title=HTTP&action=edit" title="You can edit this page. Please use the preview button before saving. [e]" accesskey="e">Create</a>
Personal tools
  • <a href="/w/index.php?title=Special:UserLogin&returnto=HTTP" title="You are encouraged to log in, it is not mandatory however. [o]" accesskey="o">Log in / create account</a>

<script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>

Browse
  • <a href="/wiki/Main_Page" title="Visit the Main Page [z]" accesskey="z">Main Page</a>
  • <a href="/wiki/Category:Solutions_by_Programming_Language">Solutions by Language</a>
  • <a href="/wiki/Category:Solutions_by_Programming_Task">Solutions by Task</a>
  • <a href="/wiki/Category:Encyclopedia">Encyclopedia</a>
  • <a href="/wiki/Special:RecentChanges" title="The list of recent changes in the wiki. [r]" accesskey="r">Recent changes</a>
  • <a href="/wiki/Special:Random" title="Load a random page [x]" accesskey="x">Random page</a>
Contribute
  • <a href="/wiki/Help:Contribute_Content">Contribute Content</a>
  • <a href="/wiki/Category:Maintenance">Pages needing attention</a>
  • <a href="/wiki/Help:Request_a_new_programming_task">Request a task</a>
  • <a href="/wiki/Help:Request_a_language_focus">Request a language</a>
Community
  • <a href="/wiki/Village_Pump:Home">Village Pump</a>
  • <a href="http://blog.rosettacode.org">Blog</a>
  • <a href="/wiki/Help:Similar_Sites">Similar sites</a>
  • <a href="/wiki/Help:IRC">Internet Relay Chat</a>
Toolbox
  • <a href="/wiki/Special:WhatLinksHere/HTTP" title="List of all wiki pages that link here [j]" accesskey="j">What links here</a>
  • <a href="/wiki/Special:Upload" title="Upload files [u]" accesskey="u">Upload file</a>
  • <a href="/wiki/Special:SpecialPages" title="List of all special pages [q]" accesskey="q">Special pages</a>
  • <a href="/w/index.php?title=HTTP&printable=yes" title="Printable version of this page [p]" accesskey="p">Printable version</a>


<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>

</body></html>