我有一个附带有accesscode的Webservices URL。我需要将访问码发布到webservices url并获得json响应。我正在使用正确的访问码和错误的访问码来获取json响应。我没有得到问题出现的地方。我需要在错误的密码进入,这里是我的代码显示警报..从webservices url获取密码并通过该密码进行访问
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。你能帮助我如何解决这一问题?
@patel的源代码最好的例子,我更新了我的代码,如你所说,我还是我的应用程序日志记录wrng密码。为了设置网址,我没有像你说的那样使用,因为我得到一个新的url作为json响应。我用你的代码更新了我的问题。你可以看到我的代码中的最后一条语句,我如何使用url。等待回复。 – 2013-03-13 06:34:32
...?accesscode = abcdtype = 1您不能在Post方法中将它传递到我的答案中。 – iPatel 2013-03-13 10:26:25