gpt4 book ai didi

iphone - 将参数传递给 Web 服务工作代码

转载 作者:行者123 更新时间:2023-12-03 21:20:09 24 4
gpt4 key购买 nike

我再次尝试使用肥皂方法,但这次我下载了查尔斯并观察我从代码创建的请求。 Chales 显示“无法解析数据(org.xml.sax.saxparser 异常:序言中不允许内容)”

这是我的代码:

   NSString *soapMsg = [[NSString alloc] initWithFormat:@"\n"                         "\n"                         ""                         "\n"                         "%@\n"                         "%@\n"                                                                                                                                       "%@\n"                         "%@\n"                         "\n"                         "\n"                         "\n",str1,str2,str3,str4];                               NSLog(soapMsg);    NSURL *url = [NSURL URLWithString:@"http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation"];    NSLog(@"url. . . .%@", url);    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];        NSLog(@"req....%@", req);     NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];    NSLog(@"msgLength. . .%@", msgLength);    [req addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];    [req addValue: @"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"];    [req addValue: msgLength forHTTPHeaderField:@"Content-Length"];    [req setHTTPMethod:@"POST"];    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];    NSLog(@"req....%@", req);    NSError *error;    NSURLResponse *response;    //NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];     NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];     if( theConnection )     {         //webData = [[NSMutableData data] retain];         NSLog(@"theConnection is OK");     }     else     {         NSLog(@"theConnection is NULL");     }     if(!response){        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Failed to Connect to the Internet" delegate:self  cancelButtonTitle:@"OK" otherButtonTitles:nil];        [alert show];        [alert release];    }    else{        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Connection Successful" message:@"Connected to the Internet" delegate:self  cancelButtonTitle:@"OK" otherButtonTitles:nil];        [alert1 show];        [alert1 release];    }} 

救命!!提前致谢!!

最佳答案

您是在问如何在您的项目中包含 ASIHTTPRequest,对吧?将 ASIHTTPRequest 的文件夹复制并粘贴到您的项目文件夹中,并将其添加到您的代码中:

#import "ASIHTTPRequest.h"

请注意ASIHTTPRequest是一个外部库,不是 iOS SDK 的一部分。

关于iphone - 将参数传递给 Web 服务工作代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5581432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com