{"id":24,"date":"2006-04-22T07:13:52","date_gmt":"2006-04-22T12:13:52","guid":{"rendered":"http:\/\/www.tigoe.com\/pcomp\/code2\/processing\/24"},"modified":"2008-01-21T21:33:19","modified_gmt":"2008-01-22T02:33:19","slug":"http-request-in-processing","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/Processing\/24\/","title":{"rendered":"HTTP Request in Processing"},"content":{"rendered":"<p>This program shows how to make a HTTP request in Processing.<\/p>\n<p><!-- technorati tags start --><\/p>\n<p style=\"text-align:right;font-size:10px;\">Technorati Tags: <a href=\"http:\/\/www.technorati.com\/tag\/networked objects\" rel=\"tag\">networked objects<\/a>, <a href=\"http:\/\/www.technorati.com\/tag\/networks\" rel=\"tag\">networks<\/a><\/p>\n<p><!-- technorati tags end --><br \/>\n<!--more--><\/p>\n<pre>\/* http client\n by Tom Igoe\n \n Starts a network client that connects to a server on port 80,\n sends an HTTP 1.1 GET request, and prints the results.\n \n created March 18, 2005\n \n *\/\nimport processing.net.*;\n\nClient client;\nint byteCount = 0;\n\nvoid setup()\n{\n  size(200, 200);\n  noStroke();\n  \/\/ open a TCP socket to the host:\n  client = new Client(this, \"myserver.com\", 80);\n\n  \/\/print the IP address of the host:\n  println(client.ip());\n\n  \/\/ send the HTTP GET request:\n  client.write(\"GET \/~myaccount\/somePage.html HTTP\/1.1\\n\");\n  client.write(\"HOST: myserver.com\\n\\n\");\n}\n\nvoid draw()\n{\n  background(0);\n  \/\/ print the results of the GET:\n  if (client.available() &gt; 0) {\n    int inByte = client.read();\n    byteCount++;\n    print((char)inByte);\n  } \n  else {\n    if (byteCount &gt; 0) {\n      println(\" I got: \" + byteCount + \" bytes.\");\n      byteCount = 0;\n      println(\"\\n\\nThat's all, folks!\\n\");\n    }\n  }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This program shows how to make a HTTP request in Processing.  \/* http client by Tom Igoe Starts a network client that connects to a server on port 80, sends an HTTP 1.1 GET request, and prints the results.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-Processing"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":0,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}