2 yomi198991 Yomi198991 于 2014.05.16 11:26 提问

MKNetworkKit调用Web Service失败

本人新手,刚接触MKNetworkKit类库,尝试调用Web Service的Login方法,不知道为什么老是失败。模拟器刚打开的时候网络状态是ReachableViaWiFi,但是我一点登录按钮,状态就变成NotReachable,是我哪里写错了吗?可是我用Safari是能连上的,这是为什么呢?

  • (IBAction)Login:(id)sender {
    self.username = self.Login_name.text;
    self.pwd = self.password.text;

    MKNetworkKitTestAppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];

    myDelegate.gs_employee_no = self.username;

    MKNetworkEngine engine = [[MKNetworkEngine alloc] initWithHostName:@"10.54.45.*:****" customHeaderFields:nil];

    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setValue:self.username forKey:@"emp_no"];
    [dic setValue:self.pwd forKey:@"password"];

    MKNetworkOperation *op = [engine operationWithPath:@"Service.asmx" params:dic httpMethod:@"POST"];

    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
    id json = [completedOperation responseString]; //有现成的返回json方法可直接调用
    //NSString *rs = (NSString *)json;
    NSDictionary *person = (NSDictionary *)json;

    NSString *name = [person objectForKey:@"userNmae"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"欢迎!"
                                                    message:name
                                                   delegate:nil
                                          cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
    alert=nil;
    name=nil;
    

    }errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示!"
                                                    message:@"Web Service失败"
                                                   delegate:nil
                                          cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
    alert=nil;
    

    }];

    [engine enqueueOperation:op];
    }

下面是报错信息

2014-05-14 17:06:58.281 MKNetworkKitTest[1921:60b] -[MKNetworkEngine reachabilityChanged:] [Line 211] Server [10.54.45.**:****] is not reachable
2014-05-14 17:06:58.564 MKNetworkKitTest[1921:60b] -[MKNetworkOperation operationFailedWithError:] [Line 1347] Wednesday, May 14, 2014 at 5:06:58 PM China Standard Time

Request

curl -X POST -H "Accept-Language: en, fr, de, zh-Hans, zh-Hant, ja, nl, it, es, ko, pt, pt-PT, da, fi, nb, sv, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us" -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" "http://10.54.45.**:****/Service.asmx" -d "emp_no=0983" -d "password=abc.123"

Response

http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="soap:Receiverhttp://www.w3.org/2001/XMLSchema">soap:Receiver xml:lang="zh-CHS">服务器无法处理请求。 ---> 根级别上的数据无效。 第 1 行,位置 1。
, [The operation couldn’t be completed. (NSURLErrorDomain error 500.)]
2014-05-14 17:09:48.594 MKNetworkKitTest[1921:60b] -[MKNetworkOperation operationFailedWithError:] [Line 1355] State: 0

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!