iphone - NSMutableURLRequest loses session information -
i have iphone app i'm trying talk rails end. i'm using nsmutableurlrequest pull data , forth. calls work fine on requests when need post data, rails app can't seem find session. i've posted code below both , post request.
this post request:
//set url nsstring *url_string = [nsstring stringwithformat:@"https://testserver.example.com/players.xml"]; nsurl *url = [nsurl urlwithstring:url_string]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:30]; //to create object in rails //we have use post request ////this format when using xml nsstring *requeststring = [[nsstring alloc] initwithformat:@"<player><team_game_id>%@</team_game_id><person_id>%@</person_id></player>", game, person]; nsdata *requestdata = [nsdata datawithbytes:[requeststring utf8string] length:[requeststring length]]; [request sethttpmethod:@"post"]; [request sethttpbody:requestdata]; nsstring *postlength = [nsstring stringwithformat:@"%d", [requestdata length]]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; //for reason rails not take application/xml [request setvalue:@"application/xml" forhttpheaderfield:@"content-type"];
the request is:
nsstring *url_string = [nsstring stringwithformat:@"https://testserver.example.com/people/find_by_passport?passport=%i", passport]; passportstring = [[nsmutablestring alloc] initwithformat:@"%i", passport]; nslog(@"the passport string %@", passportstring); nslog(url_string, nil); nsurl *url = [nsurl urlwithstring:url_string]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:30];
i @ wits end here trying find out whats going on appreciated.
faced same issue. parse response headers set-cookie header, extract cookies hand, pass them cookie:
header on subsequent requests.
if sessions in simplest, don't have worry persistence, https, domains/paths , such.
edit: found class nshttpcookiestorage. see if can of help...
Comments
Post a Comment