0

ASIHTTPRequest を使用して、チェックのために「カスタム Cookie」を送信する必要があるサイトに接続する際に問題が発生しました。

最初に、私は時々グーグルで検索し、何らかの方法で見つけましたが、解決策は、Cookie を「ドメイン」、「値」などの元の「キー」として保存するのが最も好きです。

私の質問は、「カスタム Cookie キー」を設定したい場合、どのように作成するのですか?

たとえば、「ServerId」を「キー」として Cookie に設定したいのですが、どうすればよいですか?

さて、私は次の方法を使用しましたが、うまくいきませんでした。

NSDictionary *properties = [[NSMutableDictionary alloc]init];
[properties setValue:@"serveridvalue" forKey:@"serveridKey"];
NSHTTPCookie *cookie = [[NSHTTPCookie alloc]initWithProperties:properties];

[request setUseCookiePersistence:NO];
[request setRequestcookies:[NSMutableArray arrayWithObject:cookie]];//BTW, I got a EXC_BAD_INSTRUCTION here
[request startSynchronous];

そして、ここに私の他の試みがあります:

NSString *cookie = [[NSString alloc]initWithFormat:@"serverid=%@", serverid];
[request addRequestHeader:@"Cookie" value:cookie];
[request startSynchronous];

皆さん、あなたの助けを待っています。

PS:「リクエスト」は次のように作成されました:

ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:url];

4

1 に答える 1

0

Dont know if you solved this, but you're probably getting the "EXC_BAD_INSTRUCTION" because your cookie is probably nil and youre trying to init a array and then add that to the request. There are certain fields that need included for the cookie to initialize properly. Check out this post.

Create a cookie for NSURLRequest?

于 2013-01-29T15:35:24.203 に答える