Home > Backend Development > PHP Tutorial > iOS开发后台请求报错,帮忙看下XML格式哪里有问题 急急急!!!大神们

iOS开发后台请求报错,帮忙看下XML格式哪里有问题 急急急!!!大神们

WBOY
Release: 2016-06-06 20:11:08
Original
1123 people have browsed it

报错:Entity: line 1: parser error : Start tag expected, '以下为请求XML,用的是ASIHTTPRequest请求框架,不知错在何处
com.portal.android.ExecuteAndroidchangeState

请求数据代码:
NSString *kvr = [NSString stringWithFormat:@"",@"",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:@""];
    [requestXml appendString:@""];
    [requestXml appendString:@""];
    NSString *name = [NSString stringWithFormat:@"%@%@
    ",classPath,metherName];
    [requestXml appendString:name];

    [requestXml appendString:kvrStr];
    [requestXml appendString:@""];
    [requestXml appendString:@""];

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

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

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

    <code>   //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;</code>
    Copy after login
    Copy after login

    }];

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

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

    }];

    [request startAsynchronous];
    }

回复内容:

报错:Entity: line 1: parser error : Start tag expected, '以下为请求XML,用的是ASIHTTPRequest请求框架,不知错在何处
com.portal.android.ExecuteAndroidchangeState

请求数据代码:
NSString *kvr = [NSString stringWithFormat:@"",@"",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:@""];
    [requestXml appendString:@""];
    [requestXml appendString:@""];
    NSString *name = [NSString stringWithFormat:@"%@%@
    ",classPath,metherName];
    [requestXml appendString:name];

    [requestXml appendString:kvrStr];
    [requestXml appendString:@""];
    [requestXml appendString:@""];

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

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

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

    <code>   //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;</code>
    Copy after login
    Copy after login

    }];

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

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

    }];

    [request startAsynchronous];
    }

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

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template