CIT 383: Administrative Scripting

Slides:



Advertisements
Similar presentations
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
Advertisements

HTTP – HyperText Transfer Protocol
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
How the web works: HTTP and CGI explained
Python and Web Programming
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting RSS.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Hypertext Transport Protocol CS Dick Steflik.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Java Technology and Applications
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
HTTP Protocol Specification
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
ASP.NET Web Development 1 Web Technology Basics. Browser and server roles Static (stateless) web pages Web Technology Basics #2.
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting XML.
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Web Security.
WWW, HTTP, GET, POST, Cookies Svetlin Nakov Telerik Corporation
CIT 383: Administrative Scripting
USING PERL FOR CGI PROGRAMMING
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Writing Methods.
Proxy Lab Recitation I Monday Nov 20, 2006.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
Web Server Design Week 4 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/03/10.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting HTTP.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Web Services. 2 Internet Collection of physically interconnected computers. Messages decomposed into packets. Packets transmitted from source to destination.
Summer 2007 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 1 – Introducing Ajax.
RESTful Web Services What is RESTful?
Overview of Servlets and JSP
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Directories.
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
The OWASP Foundation OWASP Education Computer based training The Basics Nishi Kumar IT Architect Specialist, FIS Chair, Software Security.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
Lecture # 1 By: Aftab Alam Department Of Computer Science University Of Peshawar Internet Programming.
HTTP – An overview.
The Hypertext Transfer Protocol
COMP2322 Lab 2 HTTP Steven Lee Feb. 8, 2017.
CIT 383: Administrative Scripting
HTTP Protocol Specification
Hypertext Transfer Protocol
Hypertext Transport Protocol
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
CIT 383: Administrative Scripting
Hypertext Transfer Protocol
Hypertext Transfer Protocol
Hypertext Transfer Protocol
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
Web Server Design Week 5 Old Dominion University
Traditional Internet Applications
HTTP Hypertext Transfer Protocol
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Hypertext Transfer Protocol
CSCI-351 Data communication and Networks
Presentation transcript:

CIT 383: Administrative Scripting HTTP and HTML CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Topics HTTP URLs Cookies Base64 CIT 383: Administrative Scripting

Web Client/Server Interaction Browser Server HTTP Request (form submission)‏ User waits Server processing HTTP Response (new web page)‏ User interaction HTTP Request (form submission)‏ Server processing User waits HTTP Response (new web page)‏ CIT 383: Administrative Scripting

HTTP: HyperText Transfer Protocol Simple request/respond protocol Request methods: GET, POST, HEAD, etc. Protocol versions: 1.0, 1.1 Stateless Each request independent of previous requests, i.e. request #2 doesn’t know you auth’d in #1. Applications responsible for handling state. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTTP Request Method URL Protocol Version Headers GET http://www.google.com/ HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 (Windows NT 5.1) Gecko/20060909 Firefox/1.5.0.7 Accept: text/html, image/png, */* Accept-Language: en-us,en;q=0.5 Cookie: rememberme=true; PREF=ID=21039ab4bbc49153:FF=4 Blank Line No Data for GET method CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTTP Response Protocol Version HTTP Response Code HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html Server: GWS/2.1 Date: Fri, 13 Oct 2006 03:16:30 GMT <HTML> ... (page data) ... </HTML> Headers Blank Line Web Page Data CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTTP Methods HEAD Same as GET, but only asks for headers, not body. GET Requests a representation of the resource. Most common method. Should not cause server to modify (write, delete) any resources. POST Submits data to be processed to the resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both. PUT Uploads a representation of the specified resource. DELETE Deletes the specified resource. TRACE Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request. From http://en.wikipedia.org/wiki/Http CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTTP Request Headers Header Description Example Accept Acceptable content types. Accept: text/plain Authorization HTTP authentication credentials. Authorization: Basic QWxhZGRpbjpvcGVuIHNl c2FtZQ== Cache-Control Caching directives Cache-Control: no cache Cookie Cookie data for server. Cookie: color=red Date Date and time sent Date: 29 Oct 2008 1:02:03 Host Name of server Host: cs.nku.edu If-Modified- Since Allows a 304 Not Modified to be returned for caching. If-Modified-Since: 29 Oct 2008 1:02:03 GMT User-Agent Browser description string Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.2) Ubuntu/8.04 Firefox/3.1 http://en.wikipedia.org/wiki/List_of_HTTP_headers CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTTP Response Headers Header Description Example Cache-Control Caching directives Cache-Control: no cache Content- Encoding Type of encoding used. Content-Encoding: gzipSer Content-Length Length of data returned. Content-Length: 1024 Content-Type Type of data returned. Content-Type: text/html Date Date and time response sent. Date: 29 Oct 2008 1:02:03 Expires Date after which data expired. Expires: 1 Nov 2008 1:02:03 Location Used in redirection Location: http://www.example.com/about/ Server Server identification string. Server: Apache/2.0.55 Set-Cookie Cookie created by server. Set-Cookie: color=red http://en.wikipedia.org/wiki/List_of_HTTP_headers CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTTP Response Codes Code Description Meaning 200 OK Standard success response. 201 Created New resource created. 301 Moved permanently Permanent redirect to new URI. 304 Not modified Safe to use page stored in cache. 307 Temporary redirect Use new URI now; try old later. 401 Unauthorized Authentication failed. 403 Forbidden Disallowed, auth will not help. 404 Not found Resource was not found. 405 Method not allowed Used GET when should use POST. 500 Internal server error Internal server error. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Net::HTTP Class Net::HTTP.get(host, path): returns resource from host, path as a string. Net::HTTP.get_response(host, path): returns HTTP response object, includes body + headers. Net::HTTP.post_form(host, path,{parameters}): returns resource from host, path as a string using POST instead of GET, sending form parameters as a hash. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Redirection Example def fetch(uri) response = Net::HTTP.get_response(uri) case response when Net::HTTPSuccess then response when Net::HTTPRedirection then fetch(response['location']) else response.error! end CIT 383: Administrative Scripting

CIT 383: Administrative Scripting URI Format <proto>://<user>@<host>:<port>/<path>?<qstr> Whitespace marks end of URL “@” separates userinfo from host “?” marks beginning of query string “&” separates query parameters %HH represents character with hex values ex: %20 represents a space RFC 1738 for URL definitions http://username:password@www.auth.com:8001/a%20spaced%20path CIT 383: Administrative Scripting

CIT 383: Administrative Scripting URI Class URI.extract(string): returns array of URI strings extracted from string. URI.extract("text http://example.com/ and mailto:test@example.com and text here also.") => ["http://example.com/", "mailto:test@example.com"] URI.join(string,string,...): joins two or more strings into a URI. URI.parse(string): creates URI object f/ string. URI.split(uri): splits URI string into protocol, host, path, query, etc. components. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Cookies Server to Client Content-type: text/html Set-Cookie: foo=bar; path=/; expires Fri, 20-Feb- 2004 23:59:00 GMT Client to Server Cookie: foo=bar RFC 2109 CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Base64 Encoding How do you send binary data using text? Email attachments (MIME). Cookies (HTTP). Base64: encode 3 bytes as 4 text characters Use characters A-Za-z0-9+/ to store 6 bits of data. Byte has 8 bits, so 3 bytes = 24 bits 4 base64 chars (6 bits each) = 24 bits Use = to pad output if input not multiple of 3 bytes. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Base64 Class encode = Base64.encode64(‘informatics‘) decode = Base64.decode64(‘aW5mb3JtYXRpY3M=‘) CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Topics Evolution of HTML HTML Structure Regular Expressions v Parsing HPricot XPath CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Evolution of HTML 1991 HTML created (only 22 tags) 1995 HTML 2.0 1996 Tables added to HTML 2.0 Jan 1997 HTML 3.2 published by W3C Dec 1997 HTML 4.0 2000 XHTML 1.0 2008 HTML 5.0 working draft published. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTML Structure <html> <title>My title</title> <body> <a href=“...”>My link</a> <h1>My header</h1> </body> </html> CIT 383: Administrative Scripting

CIT 383: Administrative Scripting HTML Structure Image from http://www.w3schools.com/HTMLDOM/default.asp CIT 383: Administrative Scripting

Why Not Regular Expressions? Angle-bracket tags are difficult to deal with. Tag regexp: <\w+\s+[^>]*> Matches <img alt=“ruby” src=“rb.png”> Doesn’t: <img alt=“ruby>” src=“rb.png”> Solution:check for > in attributes. Have to match every form of attribute name=“value” name=‘value’ name=value name CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Hpricot h = Hpricot(html-string) Creates a new HPricot::Doc object. el = h.at(string) Finds first matching Hpricot::Elements object. el = h.search(string or XPath expression) Returns array of matching objects. el.inner_html Returns HTML enclosed in element. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting XPath Searches h.search("p") Find all paragraph tags in document. doc.search("/html/body//p") Find all paragraph tags within the body tag. doc.search("//a[@src]") Find all anchor tags with a src attribute. doc.search("//a[@src='google.com']") Find all a tags with a src attribute of google.com. http://code.whytheluckystiff.net/hpricot/wiki/SupportedXpathExpressions CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Final Exam Comprehensive exam like midterm 20% concepts (focus on classes + exceptions) 80% programs (at least 2 programs like labs) Study Review the midterm practice problems. Work out your lab programs again. Solve un-assigned lab programs. Review concepts, esp. classes + exceptions. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Going Further Ruby Quiz Assignment-scale problems + solutions. http://rubyquiz.com/ Practical Ruby for System Administration If Admin Scripting II existed, this would be the text. General Ruby Books The Ruby Way, 2nd edition The Ruby Programming Language CIT 383: Administrative Scripting

CIT 383: Administrative Scripting References Michael Fitzgerald, Learning Ruby, O’Reilly, 2008. David Flanagan and Yukihiro Matsumoto, The Ruby Programming Language, O’Reilly, 2008. Hal Fulton, The Ruby Way, 2nd edition, Addison- Wesley, 2007. Robert C. Martin, Clean Code, Prentice Hall, 2008. Dave Thomas with Chad Fowler and Andy Hunt, Programming Ruby, 2nd edition, Pragmatic Programmers, 2005. CIT 383: Administrative Scripting