php - iOS开发后台请求报错,帮忙看下XML格式哪里有问题 急急急!!!大神们
怪我咯
怪我咯 2017-04-10 17:19:32
[PHP讨论组]

报错:Entity: line 1: parser error : Start tag expected, '<' not found
以下为请求XML,用的是ASIHTTPRequest请求框架,不知错在何处
<?xml version='1.0' encoding='UTF-8' standalone='yes'?><Root><method action="E"><classPath>com.portal.android.ExecuteAndroid</classPath><methodName>changeState</methodName></method><kvdata ID="" SHIP_NAME="ceshi01" CARGO_REMARK="种用硬粒小麦100111009012吨" DOCK="E201205160096297" BERTH="E201205160096300" CARGO_TYPE="0" CARGO_NAME="种用硬粒小麦" CARGO_HS_CODE="1001110090" CARGO_WEIGHT="12" BILL_INFO="" MANIFEST_INFO="" CLIENT="" ISDECL="NODECL" CREATE_ORG="江阴市外轮代理有限公司" CREATE_ORG_ID="201307220000013086" CREATE_USER_ID="201306030000007077" CREATE_USER="杨柳絮" UPDATE_USER_ID="201306030000007077" UPDATE_USER="杨柳絮" AGENTID="E201511120021555"></kvdata></Root>

请求数据代码:
NSString *kvr = [NSString stringWithFormat:@"<kvdata ID=&quot;%@&quot; SHIP_NAME=&quot;%@&quot; CARGO_REMARK=&quot;%@&quot; DOCK=&quot;%@&quot; BERTH=&quot;%@&quot; CARGO_TYPE=&quot;%@&quot; CARGO_NAME=&quot;%@&quot; CARGO_HS_CODE=&quot;%@&quot; CARGO_WEIGHT=&quot;%@&quot; BILL_INFO=&quot;%@&quot; MANIFEST_INFO=&quot;%@&quot; CLIENT=&quot;%@&quot; ISDECL=&quot;%@&quot; CREATE_ORG=&quot;%@&quot; CREATE_ORG_ID=&quot;%@&quot; CREATE_USER_ID=&quot;%@&quot; CREATE_USER=&quot;%@&quot; UPDATE_USER_ID=&quot;%@&quot; UPDATE_USER=&quot;%@&quot; AGENTID=&quot;%@&quot;>",@"",cell.shipNameTextField.text,cargoRemark,self.dockModel.t2,self.berthModel.t2,cargoType,self.cargoModel.t2,self.cargoModel.t1,cell.cargoWeightTextField.text,cell.billInfoTextField.text,@"",cell.delegateTextField.text,@"NODECL",appDelegate.userInfo.ORG_NAME,appDelegate.userInfo.ORG_ID,appDelegate.userInfo.USER_ID,appDelegate.userInfo.USER_NAME,appDelegate.userInfo.USER_ID,appDelegate.userInfo.USER_NAME,self.personModel.t2];
[req sendRequest:@"com.portal.android.ExecuteAndroid" metherName:@"changeState" kvrStr:kvr andTag:4001 andUrl:WebServeUrl];

  • (void)sendRequest:(NSString )classPath metherName:(NSString )metherName kvrStr:(NSString )kvrStr andTag:(NSInteger) tag andUrl:(NSString )url
    {
    __block ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:url]];
    // NSLog(@"%@",WebServeUrl);
    NSMutableString *requestXml = [[NSMutableString alloc] init];
    [requestXml appendString:@"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"];
    [requestXml appendString:@"<Root>"];
    [requestXml appendString:@"<method action=&quot;E&quot;>"];
    NSString *name = [NSString stringWithFormat:@"<classPath>%@</classPath><methodName>%@</methodName></method>",classPath,metherName];
    [requestXml appendString:name];

    [requestXml appendString:kvrStr];
    [requestXml appendString:@"</kvdata>"];
    [requestXml appendString:@"</Root>"];

    //NSLog(@"%@",requestXml);
    NSData *requestData = [requestXml dataUsingEncoding:NSUTF8StringEncoding];

    [request appendPostData:requestData];
    [request setRequestMethod:@"post"];

    //请求执行完的回掉
    [request setCompletionBlock:^{

       //NSLog(@"Success");
       NSData *decompressData = [request responseData];
       GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:decompressData options:0 error:Nil];
       GDataXMLElement *rootElement = [doc rootElement];
       NSArray *result = [rootElement elementsForName:@"result"];
       for (GDataXMLElement *response in result) {
           NSString *code = [[response attributeForName:@"code"] stringValue];
           NSString *msg = [[response attributeForName:@"msg"] stringValue];
           //01是成功,其余是错误
           if (![code isEqualToString:@"01"]) {
               [self showAlert:msg];
           } else {
               NSArray *datasetArray = [rootElement elementsForName:@"kvdata"];
               NSArray *kvadaArray = [rootElement elementsForName:@"dataset"];
               GDataXMLElement *data = [kvadaArray objectAtIndex:0];
               NSArray *dataArray = [data elementsForName:@"data"];
               if ([datasetArray count] > 0) {
                   [_delegate didReceiveData:datasetArray andTag:tag];
               }else{
                   [_delegate didReceiveData:dataArray andTag:tag];
               }
           }
       }
       request = nil;

    }];

    //异常出现
    [request setFailedBlock:^{

       //NSLog(@"Failed");
       [self showAlert:@"网络请求失败,请稍后再试"];
       //        [_delegate didFairToReceiveData:nil andTag:tag];

    }];

    [request startAsynchronous];
    }

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(3)
迷茫

由于把请求数据加密了,请求回调时处理数据未解密,所以导致了错误

巴扎黑

格式没错哦,你用一个支持xml的ide打开一下就可以知道有没有语法错误。。。

高洛峰

请求数据是不是有错误?
能不能把你打印请求数据的代码贴出来

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号