urlconnection - Set Cookies for URL Connection Android -


i need set cookies url connection. new android. in iphone done below:

nsurl *serverurl = [nsurl urlwithstring:@"<server url>"];  nshttpcookie *usernamecookie = [nshttpcookie cookiewithproperties:                                    [nsdictionary dictionarywithobjectsandkeys:                                    [serverurl host], nshttpcookiedomain,                                    [serverurl path], nshttpcookiepath,                                      @"username", nshttpcookiename,                                      @"<username>", nshttpcookievalue,                                      nil]];  nshttpcookie *passwordcookie = [nshttpcookie cookiewithproperties:                                    [nsdictionary dictionarywithobjectsandkeys:                                    [serverurl host], nshttpcookiedomain,                                    [serverurl path], nshttpcookiepath,                                      @"password", nshttpcookiename,                                      @"<password>", nshttpcookievalue,                                       nil]];  [[nshttpcookiestorage sharedhttpcookiestorage] setcookie:usernamecookie]; [[nshttpcookiestorage sharedhttpcookiestorage] setcookie:passwordcookie];  nsdata *responsedata = [nsurlconnection sendsynchronousrequest:[nsurlrequest requestwithurl:serverurl] returningresponse:nil error:nil]; nsstring *response = [[[nsstring alloc] initwithdata:responsedata encoding:nsutf8stringencoding]autorelease]; nslog(@"response data %@",[response description]); 

kindly if idea that.

android has similar. create cookies , add them cookie storage, , available when requested server in http connection.

to create , add cookie use following code:

cookiemanager cookiemanager = new cookiemanager(); cookiehandler.setdefault(cookiemanager); httpcookie cookie = new httpcookie("lang", "fr"); cookie.setdomain("twitter.com"); cookie.setpath("/"); cookie.setversion(0); cookiemanager.getcookiestore().add(new uri("http://twitter.com/"), cookie); 

for more information, see httpurlconnection , cookiemanager


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -