Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between cookie and string in request header

Tags:

java

cookies

Cookie is nothing but a small piece of information most of the times a string in the request header send by the client to server. If i add one more string to the request header at server in java like conn.addRequestProperty("iPlanetDirectoryPro", token); then is there any difference between the two? Can the second one be also considered as a cookie.

Regards,

Maclean Maurice Pinto

like image 357
Maclean Pinto Avatar asked Jan 20 '14 04:01

Maclean Pinto


People also ask

What is the difference between a cookie and a header?

HTTP headers are used to pass additional information with HTTP response or HTTP requests. A cookie is an HTTP request header i.e. used in the requests sent by the user to the server. It contains the cookies previously sent by the server using set-cookies. It is an optional header.

Are cookies in request header?

The Cookie HTTP request header contains stored HTTP cookies associated with the server (i.e. previously sent by the server with the Set-Cookie header or set in JavaScript using Document. cookie ). The Cookie header is optional and may be omitted if, for example, the browser's privacy settings block cookies.

How is a cookie represented in an HTTP request and an HTTP response?

Cookies are set using the Set-Cookie header field, sent in an HTTP response from the web server. This header field instructs the web browser to store the cookie and send it back in future requests to the server (the browser will ignore this header field if it does not support cookies or has disabled cookies).


1 Answers

You'll want to read the HTTP specification (message headers) and the HTTP State Management specification.

The HTTP specification provides message headers

Each header field consists of a name followed by a colon (":") and the field value.

For example, you could have

Content-Length:42

This is a header.

The HTTP State Management specification defines the Cookie and Set-Cookie headers. Those are two specific headers that are used for achieving state in HTTP request and response cycles (HTTP is a stateless protocol).

So

conn.addRequestProperty("iPlanetDirectoryPro", token); then is there any difference between the two?

Yes, there is a big difference. The above is a simple request header. It has nothing to do with a Cookie.

like image 165
Sotirios Delimanolis Avatar answered Nov 09 '22 16:11

Sotirios Delimanolis