【发布时间】:2012-03-02 14:12:17
【问题描述】:
大家!我的英语很差,很抱歉。
我想在我的测试 iOS 应用程序中实现一个功能。
有一个 .NET Webservice API 就像
“https://xxx.xxx.xx.xxx/FMS/Pages/Service/FMService.svc/Login”
我想用两个参数连接API:user和pass
使用GET方法,url会是这样的:
“https://xxx.xxx.xx.xxx/FMS/Pages/Service/FMService.svc/Login?user=xxx&pass=xxx”
如果登录,Webservice 将返回一个 JSON 值,就像 {"d":"success"}
如果不是,它也会返回一个 JSON 值,例如 {"d":"failure"}
我正在使用 ASIHTTPRequest 框架和 JSON 框架
我不知道如何实现该功能。所以请帮助我,非常感谢。
祝你好运!
NSURL *url = [NSURL URLWithString:@"https://192.168.1.245/FMS/Pages/Service/FMService.svc/Login?user=jiangxd&pass=123456"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:@"Accept" value:@"application/json"];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request setRequestMethod:@"GET"];
[request setDelegate:self];
[request startAsynchronous];
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *unlockCode = [responseDict objectForKey:@"d"];
NSLog(@"%@",unlockCode);
unlockCode 始终为空...我不明白为什么!
NSURL *url = [NSURL URLWithString:@"https://192.168.1.245/FMS/Pages/Service/FMService.svc/Login?user=jiangxd&pass=123456"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error)
{
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *unlockCode = [responseDict objectForKey:@"d"];
NSLog(@"%@",unlockCode);
}
else
{
NSLog(@"%@",[error description]);
}
现在我将 startAsynchronous 更改为 startSynchronous 但也有错误:
Error Domain=ASIHTTPRequestErrorDomain Code=1 “发生连接失败:SSL 问题(可能的原因可能包括错误/过期/自签名证书,时钟设置为错误日期)” UserInfo=0x6b81640 {NSUnderlyingError=0x6b811b0 “操作无法完成。(OSStatus 错误 -9807。)”,NSLocalizedDescription=发生连接失败:SSL 问题(可能的原因可能包括错误/过期/自签名证书,时钟设置为错误日期)}
注意:网址是 https,而不是 http!(这是我收到错误的原因吗?)
但是如果我直接用浏览器访问url,Webservice会返回正确的值...
谢谢!
【问题讨论】:
标签: ios web-services get