gpt4 book ai didi

ios - NSURLConnection 返回多个 php session ID

转载 作者:行者123 更新时间:2023-11-29 02:09:50 24 4
gpt4 key购买 nike

我已经使用 NSURLConnection 连接到 Web 服务(其余)并获取响应和 cookie 以供稍后使用。但 NSURLConnection 返回多个 php session ID。这应该是错误的,因为当我使用 REST Easy(firefox Rest 应用程序)测试它时,它给出了以下输出。

Set-Cookie  PHPSESSID=1hk82sac38si2e58l2vvcduqh2; path=/; HttpOnly

但是 NSURLConnection 给出了这个,

@"PHPSESSID=f5p9ihq38sg4aeq3a98374s074; path=/; HttpOnly, PHPSESSID=e73ru08mtaf22t9rup33qjmkj5; path=/; HttpOnly, Loggedin=True;

(有两个PHPSESSID)

这是我的代码,

NSURL *nsurl = [NSURL URLWithString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nsurl cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:120.0];

request.HTTPMethod = @"POST";
NSString *stringData = [NSString stringWithFormat:@"username=%@&password=%@&grant_type=%@&client_id=%@", username, password, grantType, clientId];
NSData *requestBodyData = [stringData dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = requestBodyData;

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

我用所有缓存策略值检查了这一点。但是输出是一样的。

NSURLRequestUseProtocolCachePolicy = 0, 
NSURLRequestReloadIgnoringLocalCacheData = 1,
NSURLRequestReturnCacheDataElseLoad = 2,
NSURLRequestReturnCacheDataDontLoad = 3,

如何获取正确的 php session ID?

最佳答案

使用这个片段-

NSMutableURLRequest *request = nil;
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];

NSString *post = [NSString stringWithFormat:@"username=%@&password=%@&grant_type=%@&client_id=%@", username, password, grantType, clientId];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setTimeoutInterval: 120];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

关于ios - NSURLConnection 返回多个 php session ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29405706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com