Introduction to HTTP: Request and Response Handling
VerifiedAdded on 2025/08/25
|5
|770
|200
AI Summary
Desklib provides solved assignments and past papers to help students understand complex concepts.

1. Hypertext Transfer Protocol
Q1:
Ans1: Request line: Method Request-URI HTTP-Version
1. Method: - The method to perform indicated by the request method, which is used to perform the
same of the resource that is identified by given request-URI
2. Request-URI: The request URI used when the resources are needed to be applied to the request.
It can be called as abs_path or absoluteURI.
3. HTTP-Version: The Http protocol version can be indicated with the help of the HTTP-version. It
can be 1.0 or 1.1
Q2:
Ans2: With the help of the query string, the parameters as CGI GET can pass.
e.g. http://www.abc.com?key1=val1&key2=val2
In the given mentioned example, val1 can be defined as value and key 1 is defined as first
parameter’s key. With the help of ‘&’ these parameters can be separated.
Q3:
Ans3: The URL’s generally contains reserved, unsafe and non-ASCII characters. These can be
converted in a format that is universally accepted as well, can be understood by all servers and web
browsers with the help of Percent Encoding. The method of conversion includes conversion of
characters into one or more bytes. Then each byte is represented by two hexadecimal digits
preceded by a per cent sign (%) - (e.g. %xy). A per cent sign can represent the escape character.
Q4:
Ans4: The Response line: HTTP-Version Status-Code Reason-Phrase
1. HTTP-Version: The HTTP protocol version can be indicated with the help of the HTTP-version.
It can be 1.0 or 1.1
2. Reason-Phrase: Reason-Phrase use to explain the ways in which the request was executed. In the
case if there is any failure, ‘Not found’ will be indicated with a reason.
3. Status-Code: It is termed to be the 3-digit integer, which tells about the way request was
executed. e.g. 400 Bad request-line
Q5:
Ans5: The third piece of information called as Host Header is used to uniquely identify a Web
domain in addition to the port number and IP address.
The results will not be generated in case of the absence of Host header when the server is a virtual
host that does not have the own IP address to make a difference with the virtual host. Hence, it is
compulsory.
Q1:
Ans1: Request line: Method Request-URI HTTP-Version
1. Method: - The method to perform indicated by the request method, which is used to perform the
same of the resource that is identified by given request-URI
2. Request-URI: The request URI used when the resources are needed to be applied to the request.
It can be called as abs_path or absoluteURI.
3. HTTP-Version: The Http protocol version can be indicated with the help of the HTTP-version. It
can be 1.0 or 1.1
Q2:
Ans2: With the help of the query string, the parameters as CGI GET can pass.
e.g. http://www.abc.com?key1=val1&key2=val2
In the given mentioned example, val1 can be defined as value and key 1 is defined as first
parameter’s key. With the help of ‘&’ these parameters can be separated.
Q3:
Ans3: The URL’s generally contains reserved, unsafe and non-ASCII characters. These can be
converted in a format that is universally accepted as well, can be understood by all servers and web
browsers with the help of Percent Encoding. The method of conversion includes conversion of
characters into one or more bytes. Then each byte is represented by two hexadecimal digits
preceded by a per cent sign (%) - (e.g. %xy). A per cent sign can represent the escape character.
Q4:
Ans4: The Response line: HTTP-Version Status-Code Reason-Phrase
1. HTTP-Version: The HTTP protocol version can be indicated with the help of the HTTP-version.
It can be 1.0 or 1.1
2. Reason-Phrase: Reason-Phrase use to explain the ways in which the request was executed. In the
case if there is any failure, ‘Not found’ will be indicated with a reason.
3. Status-Code: It is termed to be the 3-digit integer, which tells about the way request was
executed. e.g. 400 Bad request-line
Q5:
Ans5: The third piece of information called as Host Header is used to uniquely identify a Web
domain in addition to the port number and IP address.
The results will not be generated in case of the absence of Host header when the server is a virtual
host that does not have the own IP address to make a difference with the virtual host. Hence, it is
compulsory.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Q6:
And6: The type of content that is passed in the response can be described with the help of the
Content-type header. The various kinds of these called as MIME types. When text/HTML is in
human-readable format the mime, type is used. Moreover, if it is not in human-readable form than
mime type of application/HTML format is used.
2. Observing HTTP in action
Use telnet to download the file "example_1.html" from http://abc.com. Show the output report and
the command in the report.
Use telnet to attempt to download the file "example_2.html" from http://abc.com. Show the output
report and the command in the report.
And6: The type of content that is passed in the response can be described with the help of the
Content-type header. The various kinds of these called as MIME types. When text/HTML is in
human-readable format the mime, type is used. Moreover, if it is not in human-readable form than
mime type of application/HTML format is used.
2. Observing HTTP in action
Use telnet to download the file "example_1.html" from http://abc.com. Show the output report and
the command in the report.
Use telnet to attempt to download the file "example_2.html" from http://abc.com. Show the output
report and the command in the report.

3. netSrvDemo
Test netSrvDemo and Build. For this, there will be a need for two command line windows. In first
command line window, invoke the telnet command with the host "localhost" and the port number
9991 as arguments. In another window, invoke netSrvDemo. You need to first need to enter some
text and then press enter. Take a screenshot and paste it in your report.
From netSrvDemo.c copy the function main() into your report, and comment every line of code.
int main(int argc, char **argv)
Test netSrvDemo and Build. For this, there will be a need for two command line windows. In first
command line window, invoke the telnet command with the host "localhost" and the port number
9991 as arguments. In another window, invoke netSrvDemo. You need to first need to enter some
text and then press enter. Take a screenshot and paste it in your report.
From netSrvDemo.c copy the function main() into your report, and comment every line of code.
int main(int argc, char **argv)
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

{ int kg1; // called as file descriptor
char line[MaxLineLen+1]; // request data can be store in buffer
// netSry will be new object
// A network object use to Communicates with client
csc_srv_t *ntp = csc_srv_new(); assert(ntp!=NULL);
// set value of back log and the IP, PORT to network object
int c = csc_srv_setAddr(ntp, "127.0.0.1", 9991, -1); assert(c);
// For successful connection
while ((kg1 = csc_srv_accept(ntp)) >= 0) // from client connection will be accept
{
// print on stdout stream and fetch the IP Address of request
fprintf(stdout, "Connection from %s\n", csc_srv_acceptAddr(ntp));
// Convert file descriptor to input and output streams.
int kg0 = dup(kg1);
assert(kg0!=-1); // create the clone of fd0 to fd1
// for tcp input stream, create FILE object
FILE *tcpIn = fdopen(kg1, "r"); assert(tcpIn!=NULL);
// for tcp ouput stream, create FILE object
FILE *tcpOut = fdopen(fd1, "w"); assert(tcpOut!=NULL);
// Do input/output.
// read from line buffer to tcp input stream connection
csc_fgetline(tcpIn,line,MaxLineLen);
// on stdout print the request line
fprintf(stdout, "Got line: \"%s\"\n", line);
// to tcp out stream print the request line
fprintf(tcpOut, "You said \"%s\"\n", line);
// here buffer will be clear
char line[MaxLineLen+1]; // request data can be store in buffer
// netSry will be new object
// A network object use to Communicates with client
csc_srv_t *ntp = csc_srv_new(); assert(ntp!=NULL);
// set value of back log and the IP, PORT to network object
int c = csc_srv_setAddr(ntp, "127.0.0.1", 9991, -1); assert(c);
// For successful connection
while ((kg1 = csc_srv_accept(ntp)) >= 0) // from client connection will be accept
{
// print on stdout stream and fetch the IP Address of request
fprintf(stdout, "Connection from %s\n", csc_srv_acceptAddr(ntp));
// Convert file descriptor to input and output streams.
int kg0 = dup(kg1);
assert(kg0!=-1); // create the clone of fd0 to fd1
// for tcp input stream, create FILE object
FILE *tcpIn = fdopen(kg1, "r"); assert(tcpIn!=NULL);
// for tcp ouput stream, create FILE object
FILE *tcpOut = fdopen(fd1, "w"); assert(tcpOut!=NULL);
// Do input/output.
// read from line buffer to tcp input stream connection
csc_fgetline(tcpIn,line,MaxLineLen);
// on stdout print the request line
fprintf(stdout, "Got line: \"%s\"\n", line);
// to tcp out stream print the request line
fprintf(tcpOut, "You said \"%s\"\n", line);
// here buffer will be clear
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

fflush(tcpOut);
// Close the streams of tcp streams
fclose(tcpOut);
fclose(tcpIn);
}
// Free resources.
csc_srv_free(ntp); // clear the memory of network object
exit(0); // end of function execution
}
// Close the streams of tcp streams
fclose(tcpOut);
fclose(tcpIn);
}
// Free resources.
csc_srv_free(ntp); // clear the memory of network object
exit(0); // end of function execution
}
1 out of 5

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.