【问题标题】:xcode objective c soap xml 3g don't workxcode 目标 c 肥皂 xml 3g 不起作用
【发布时间】:2016-09-23 10:42:18
【问题描述】:
- (void)viewDidLoad
 {
[super viewDidLoad];
 NSString *id=@"1";
 NSString *GetExRequest = [NSString stringWithFormat:@"<SOAP-     ENV:Envelope \n"
                     "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
                     "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
                     "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"
                     "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
                     "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
                     "<SOAP-ENV:Header> \n"
                     "<UserName xmlns=\"CH1\">a1</UserName>\n"
                     "<Password xmlns=\"CH2\">a2</Password>\n"
                     "</SOAP-ENV:Header> \n"
                     "<SOAP-ENV:Body> \n"
                     "<NewsGet xmlns=\"http://tempuri.org/\">\n"
                     "<id>%@</id> \n"
                     "</NewsGet> \n"
                     "</SOAP-ENV:Body> \n"
                     "</SOAP-ENV:Envelope>\n", id];
 NSURL *url = [NSURL URLWithString:@"https:/www.a.com/Service1.svc"];
 NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
 NSString *msgLength = [NSString stringWithFormat:@"%d",GetExRequest length]];
 [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
 [theRequest addValue: @"http://tempuri.org/IService1/NewsGet"  forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [GetExRequest dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] init];
 }
else
{
 NSLog(@"theConnection is NULL");
 }
itemArray =[[NSMutableArray alloc] init];

 }

-(void)connection:(NSURLConnection *)connection didReceiveData: (NSData *)data
{
[webData appendData:data];
}

您好,我在 Objective-c 上的 Web 服务连接有问题。在 3G 连接上,我们的连接速度太慢或无法正常工作。但在 WiFi 上,我的应用程序运行良好。 3G 连接速度很快,但我不明白为什么会出现这种变慢。我应该为 3G 做些额外的事情吗?

当我在这部分设置断点时,在 3G 上它有时会进入 didReceiveData 函数。但在wifi上,它总是进入。

【问题讨论】:

    标签: objective-c xcode soap 3g


    【解决方案1】:

    根据我在许多项目中的经验,您的服务器最近响应可能是您在3G 连接中的设备上收到延迟回复的原因。

    所以我的解决方法是将默认超时更改为我的请求的显式设置超时。

    检查一下

    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:40.0];
    

    使用您的超时进行正确响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多