Yomi198991 2014-05-16 03:26
浏览 3271

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集