我有一个附加访问代码的 Web 服务 URL。我需要将访问代码发布到 Web 服务 URL 并获得 json 响应。我收到了带有正确访问码和不正确访问码的 json 响应。我没有得到问题出现的地方。当输入错误的密码时,我需要显示警报。
这是我的代码:
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@",[txtsecurecode text]];
NSLog(@"PostData: %@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidateAccess?accesscode=abcdtype=1"]]];
NSURL *url;
// I need to parse it into url here .
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn= [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
如果我输入错误的密码,我会登录失败,没关系。当我更正密码时,它不会显示该 URL 的内容。我们需要将请求解析为 URL。