SocketTools .NET Edition

HttpClient.GetCookie Method (String, String)

Return information about the specified cookie.

[Visual Basic]
Overloads Public Function GetCookie( _
   ByVal cookieName As String, _
   ByRef cookieValue As String _
) As Boolean
[C#]
public bool GetCookie(
   string cookieName,
   ref string cookieValue
);

Parameters

cookieName
A string which specifies the name of the cookie to return information about. To obtain a list of cookies which have been set by the server, use the CookieCount and CookieName properties.
cookieValue
A string passed by reference which will contain the value of the specified cookie when the method returns.

Return Value

This method returns a Boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

The Hypertext Transfer Protocol uses special tokens called "cookies" to maintain persistent state information between requests for a resource. These cookies are exchanged between the client and server by setting specific header fields. When a server wants the client to use a cookie, it will include a header field named Set-Cookie in the response header when the client requests a resource. The client can then take this cookie and store it, either temporarily in memory or permanently in a file on the local system. The next time that the client requests a resource from that server, it can send the cookie back to the server by setting the Cookie header field. The GetCookie method searches for a cookie set by the server in the Set-Cookie header field. The SetCookie method creates or modifies the Cookie header field for the next resource requested by the client.

There are two general types of cookies that are used by servers. Session cookies exist only for the duration of the client session; they are stored in memory and not saved in any kind of permanent storage. When the client application terminates, session cookies are deleted and no longer used. Persistent cookies are stored on the local system and are used by the client until their expiration time. It is the responsibility of the client application to store persistent cookies; applications may use a flat text file, a database or any other storage method available.

See Also

HttpClient Class | SocketTools Namespace | HttpClient.GetCookie Overload List