A very common requirement when connecting to a server from the iPhone or within a UIWebView is the ability to set a cookie. Cookies are often used for authentication in particular. Fortunately there is a nice way to set a global cookie for any external connections your app makes using NSHttpCookieStorage. The function below sets a global cookie with the specified domain, name and value (the path used is /):
+ (void) setCookie:(NSString *)cookieName:(NSString *)cookieValue:(NSString *)cookieDomain { NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys: cookieDomain, NSHTTPCookieDomain, cookieName, NSHTTPCookieName, cookieValue, NSHTTPCookieValue, @"/", NSHTTPCookiePath, nil]; [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:[NSHTTPCookie cookieWithProperties:properties]]; }
……
Need cheap generic VIAGRA?…