登録フォームを処理しており、安全な POST 要求を使用する必要があります。
NSJSONSerialization
変数と一緒に使用すると、data
うまく機能します。エラーなし。
問題は、 を呼び出して変数sendSynchronousRequest
を呼び出そうとすると、が「その電子メールのユーザーが既に存在します」と表示されることです。NSJSONSerialization
secureData
registrationError
どうすればこれを回避できますか?
ここに私が持っているコードがあります:
NSData *data = [NSData dataWithContentsOfURL:registrationURL];
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:registrationURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
[postRequest setHTTPMethod:@"POST"];
[postRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[postRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[postRequest setValue:[NSString stringWithFormat:@"%d", data.length] forHTTPHeaderField:@"Content-Length"];
[postRequest setHTTPBody:data];
NSURLResponse *response;
NSError *error;
NSData *secureData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
NSLog (@"%@", error);
if (secureData != nil)
{
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:secureData options:kNilOptions error:&error];
NSString *registrationError = [json objectForKey:@"error"];
NSLog(@"%@", registrationError);
}
編集: POST なしで動作するコードは次のとおりです。
NSData *data = [NSData dataWithContentsOfURL:registrationURL];
if (data != nil)
{
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *registrationError = [json objectForKey:@"error"];
NSLog(@"%@", registrationError);
}