我正在使用ASIHTTPRequest [request startAsynchronous]
功能向我的webservice api发送请求以登录。如果请求正常,则返回json值。然后我发送另一个请求以获取用户的信息,但在这里我收到错误。
这是我的代码:
-(void)login
{
[usernameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
username = [usernameTextField text];
password = [passwordTextField text];
if ( ([username length] == 0 ) || ([password length] == 0 ))
{
...
}
else
{
NSString *URL = [NSString stringWithFormat:@"https://xxx.xxx.xx.xx/FMS/Pages/Service/FMService.svc/Login?user=%@&pass=%@",username,password];
NSURL *requestURL = [NSURL URLWithString:URL];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:requestURL];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startAsynchronous];
}
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSError *error = [request error];
if (!error)
{
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *unlockCode = [responseDict objectForKey:@"d"];
if ( [unlockCode isEqualToString:@"successful"] )
{
NSURL *url = [NSString stringWithFormat:@"https://xxx.xxx.xx.xx/FMS/Pages/Service/FMService.svc/GetUserInfo?user=%@",username];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request startSynchronous];**//THERE IS AN ERROR**
NSError *error = [request error];
if (!error)
{
NSDictionary *responseDict = [responseString JSONValue];
NSString *realName = [responseDict objectForKey:@"RealName"];
NSLog(@"%@",realName);
}
}
else
{
//...
}
}
else
{
NSLog(@"%@",[error description]);
}
}
有一个错误:
[__ NSCFString absoluteURL]:发送到实例的无法识别的选择器 0x69ef4b0
另一个错误:
void SendDelegateMessage(NSInvocation *):delegate (_selectionLayoutChangedByScrolling :)等待后无法返回 10秒主运行循环模式:kCFRunLoopDefaultMode
答案 0 :(得分:7)
此行不正确:
NSURL *url = [NSString stringWithFormat:@"https://xxx.xxx.xx.xx/FMS/Pages/Service/FMService.svc/GetUserInfo?user=%@",username];
应该改为:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://xxx.xxx.xx.xx/FMS/Pages/Service/FMService.svc/GetUserInfo?user=%@",username]];