WWW, HTTP, Ajax, Jsonp: Telerik Software Academy
WWW, HTTP, Ajax, Jsonp: Telerik Software Academy
HTTP Request
HTTP Response
AJAX Requests
Same-Origin Policy
Workarounds
JSONP
6
WWW Infrastructure (2)
Client’s browser renders Web pages returned by
the Web servers
Pages are in HTML (Hyper Text Markup Language)
Browsers show the text, graphics, sounds, etc.
HTML pages contain hyperlinks to other pages
The entire WWW system runs over standard
networking protocols
TCP, DNS, HTTP, FTP, …
The HTTP protocol is fundamental for WWW
7
URL
Uniform Resource Locator (URL)
Unique resource location in WWW, e.g.
http://yoursite.com:8080/path/index.php?id=27&lang=en
http://www.google.bg/search?sourceid=navclient&ie=
UTF-8&rlz=1T4GGLL_enBG369BG369&q=http+get+vs+post
http://bg.wikipedia.org:80/wiki/%D0%A2%D0%B5%D0%BB
%D0%B5%D1%80%D0%B8%D0%B3
http://www.google.bg/search?&q=бира
10
HTML, XML, JSON, RSS
Comparing the Common Web Data Formats
HTML
Hyper Text Markup Language (HTML)
Notation for describing formatted text with
images and hyperlinks
Interpreted and displayed by the Web browsers
A Web (HTML) page consists of:
HTML file
CSS stylesheet file (optional)
A bunch of images (optional)
Other resources (optional)
12
HTML
HTML is straight-forward and easy to learn
HTML documents are plain text files
Easy to add formatting, hyperlinks, bullets, etc.
Images can be added as separate files
Can be automatically generated by authoring
programs
Tools to help users creating HTML pages
E.g. FrontPage, Dreamweaver, Visual Studio
WYSIWYG HTML editors
13
HTML – Example
<html>
<head><title>HTML Example</title></head>
<body>
<h1>Heading 1</h1>
<h2>Sub heading 2</h2>
<h3>Sub heading 3</h3>
<p>This is my first paragraph</p>
<p>This is my second paragraph</p>
<div align="center"
style="background:skyblue">
This is a div</div>
</body>
</html>
14
XML
XML is markup-language for encoding
documents in machine-readable form
Text-based format
Consists of tags, attributes and content
Provide data and meta-data in the same time
<?xml version="1.0"?>
<library>
<book><title>HTML 5</title><author>Bay Ivan</author></book>
<book><title>WPF 4</title><author>Microsoft</author></book>
<book><title>WCF 4</title><author>Kaka Mara</author></book>
<book><title>UML 2.0</title><author>Bay Ali</author></book>
</library>
15
RSS
RSS (Really Simple Syndication)
17
JSON
JSON (JavaScript Object Notation)
Request-response model
Text-based format
Relies on unique resource URLs
Provides resource metadata (e.g. encoding)
Stateless (cookies can overcome this)
20
HTTP: Request-Response Protocol
Client program Server program
Running on end host Running at the server
E.g. Web browser E.g. Web server
Requests a resource Provides resources
GET /index.html
HTTP/1.0
HTTP/1.0 200 OK
"Welcome to our
Web site!"
21
Example: Hyper Text
Transfer Protocol
HTTP request:
GET /academy/about.aspx HTTP/1.1
Host: www.telerik.com
User-Agent: Mozilla/5.0
<CRLF> The empty line
denotes the end of
HTTP response: the request header
HTTP/1.1 200 OK
Date: Mon, 5 Jul 2010 13:09:03 GMT
Server: Microsoft-HTTPAPI/2.0
Last-Modified: Mon, 12 Jul 2010 15:33:23 GMT
Content-Length: 54
<CRLF>
The empty line
<html><title>Hello</title> denotes the end of
Welcome to our site</html> the response header
22
HTTP Request Message
Request message sent by a client consists of
Request line – request method (GET, POST,
HEAD, ...), resource URI, and protocol version
Request headers – additional parameters
Body – optional data
E.g. posted form data, files, etc.
23
HTTP GET Request – Example
Example of HTTP GET request:
24
HTTP POST Request – Example
Example of HTTP POST request:
POST /webmail/login.phtml HTTP/1.1
Host: www.abv.bg
Accept: */* HTTP request line
Accept-Language: bg
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0(compatible;MSIE 6.0;
Windows NT 5.0)
Connection: Keep-Alive
Cache-Control: no-cache HTTP headers
Content-Length: 59
<CRLF>
LOGIN_USER=mente The request body contains
DOMAIN_NAME=abv.bg the submitted form data
LOGIN_PASS=top*secret!
<CRLF>
25
Conditional HTTP GET – Example
Example of HTTP conditional GET request:
27
HTTP Response – Example
Example of HTTP response from the Web server:
HTTP response status line
HTTP/1.1 200 OK
Date: Fri, 17 Jul 2010 16:09:18 GMT+2
Server: Apache/2.2.14 (Linux)
Accept-Ranges: bytes
Content-Length: 84 HTTP
Content-Type: text/html response
<CRLF> headers
<html>
<head><title>Test</title></head>
<body>Test HTML page.</body>
</html> The HTTP
response body
28
HTTP Response – Example
Example of HTTP response with error result:
HTTP/1.1 404 Not Found Response status line
Date: Fri, 17 Jul 2010 16:09:18 GMT+2
Server: Apache/2.2.14 (Linux)
Connection: close HTTP
Content-Type: text/html response
<CRLF>
<HTML><HEAD>
headers
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /img/telerik-logo.gif was not
found on this server.<P>
<HR><ADDRESS>Apache/2.2.14 Server at Port
80</ADDRESS>
The HTTP response body
</BODY></HTML>
29
Content-Type and Disposition
The Content-Type header at the server
specifies how the output should be processed
Examples: UTF-8 encoded HTML page.
Will be shown in the browser.
Content-Type: text/html; charset=utf-8
Content-Type: application/pdf
Content-Disposition: attachment;
filename="Financial-Report-April-2010.pdf"
GET
Return the specified resource, run a program at
the server, or just download file, …
HEAD
Return the meta-data associated with a resource
(headers only)
POST
Update a resource, provide input data for
processing at the server, …
31
HTTP Response Codes
HTTP response code classes
1xx: informational (e.g., “100 Continue”)
2xx: success (e.g., “200 OK”)
3xx: redirection (e.g., “304 Not Modified”, "302
Found")
4xx: client error (e.g., “404 Not Found”)
5xx: server error (e.g., “503 Service Unavailable”)
"302 Found" is used for redirecting the Web
browser to another URL
32
Browser Redirection
HTTP browser redirection example
33
Web Services
Web Services and SOA Architecture
Web Services
A web service is a method of communication
between two devices in WWW
The server device exposes services
The client consumes these services
Web services are a main part of the SOA
architecture
Database and Business logic on the server
The server exposes public services
UI logic on the client
Consumes these services
RESTful Web Services
Lightweight Architecture for Web Services
What is REST?
"Representational state transfer (REST)
is a style of software architecture for
distributed hypermedia systems such as
the World Wide Web."
http://en.wikipedia.org/wiki/Representational_State_Transfer
41
AJAX
AJAX uses HTTP
44
Origin Determination Rules
Origin is defined using
Domain name (e.g. example.com)
Application layer protocol (e.g. http)
Port number (not all browsers!)
Two resources are of the same origin if all of the
above match
45
Origin Determination Example
Say we have a resource at
http://www.example.com/dir/page.html
The following table shows outcomes of origin
checks with resources at similar URLs
46
Relaxing Same Origin Policy
Same origin policy is sometimes too restrictive
Large sites with lots of subdomains
Accessing web services
Ways of "relaxing"
document.domain – can be set to a
superdomain when in proper subdomain
Cross document messaging – HTML5,
postMessage() to page in <iframe>
Cross Origin Resource Sharing
Workaround – JSONP
47
JSONP
i.e. not listening to mommy
JSONP
JSON with padding (also JSON prefix)
51
Web Developer Tools
Simulating and Tracking Web Traffic
Web Developer Tools
Firebug plug-in for Firefox
A must have for Web developers
The ultimate tool for monitoring, editing and
debugging HTTP, HTML, CSS, JavaScript, etc.
Free, open-source – www.getfirebug.com
Fiddler – HTTP proxy
54
HTTP and AJAX
курсове и уроци по програмиране, уеб дизайн – безплатно BG Coder - онлайн състезателна система - online judge
курсове и уроци по програмиране – Телерик академия форум програмиране, форум уеб дизайн
уроци по програмиране и уеб дизайн за ученици ASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NET
http://schoolacademy.telerik.com
програмиране за деца – безплатни курсове и уроци ASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC
безплатен SEO курс - оптимизация за търсачки алго академия – състезателно програмиране, състезания
курсове и уроци по програмиране, книги – безплатно от Наков курс мобилни приложения с iPhone, Android, WP7, PhoneGap
уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop Дончо Минков - сайт за програмиране
free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране
безплатен курс "Качествен програмен код"
безплатен курс "Разработка на софтуер в cloud среда" C# курс, програмиране, безплатно
Free Trainings @ Telerik Academy
“C# Programming @ Telerik Academy
csharpfundamentals.telerik.com