Iphone 无法从服务器共享点获取响应 -(NSString*)getSoap{ NSString*getEnvelopeData=[NSString stringWithFormat: @“\n” “\n” “\n” "http://tempuri.org/IHelloWorldService/GetData\n“ “urn:uuid:e2c3af4e-5d69-4fd8-94bd-0e0f00976dad\n” “\n” "http://www.w3.org/2005/08/addressing/anonymous\n“ “\n” “\n” “\n” “\n” “0\n” “\n” “\n” “\n”]; 返回getEnvelopeData; } -(无效)加载请求{ NSString*soapMessage=[self-getSoap]; NSLog(@“soapMessage%@”,soapMessage); NSString*urlString=@”http://l-156024038.testad.com:9000/HelloWorldService.svc"; NSURL*url=[NSURL URLWithString:urlString]; NSMutableURLRequest*theRequest=[[NSMutableURLRequest alloc]initWithURL:url]; NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]]; [请求设置值:@“gzip”用于HttpHeaderField:@“接受编码”]; [theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”]; [theRequest addValue:msgLength for HttpHeaderField:@“内容长度”]; [HttpHeaderField的请求附加值:@“l-15620438.testad.com:@“主机”]; [TheRequestAddValue:@“GetData”用于HttpHeaderField:@“SOAPAction”]; [请求设置值:@“基本”用于HttpHeaderField:@“授权”]; //theRequest=[NSMutableUrlRequestWithURL:url缓存策略:NSURLRequestReloadIgnoringLocal和RemoteCacheData timeoutInterval:45]; [TheRequestSetHttpMethod:@“获取”]; [TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding]; 连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self]; if(连接) { webData=[NSMutableData]; } 其他的 { NSLog(@“连接为空”); } } //此时,连接已设置,委托已设置为self,现在是使用连接委托方法的时候了。我们将使用四种方法: -(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应{ NSLog(@“响应值%@”,响应); } -(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据 { [webData:data]; NSLog(@“数据接收%@”,webData); } -(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误{ NSLog(@“连接错误%@”,错误); }
从上面的代码中,我无法从服务器获得响应Iphone 无法从服务器共享点获取响应 -(NSString*)getSoap{ NSString*getEnvelopeData=[NSString stringWithFormat: @“\n” “\n” “\n” "http://tempuri.org/IHelloWorldService/GetData\n“ “urn:uuid:e2c3af4e-5d69-4fd8-94bd-0e0f00976dad\n” “\n” "http://www.w3.org/2005/08/addressing/anonymous\n“ “\n” “\n” “\n” “\n” “0\n” “\n” “\n” “\n”]; 返回getEnvelopeData; } -(无效)加载请求{ NSString*soapMessage=[self-getSoap]; NSLog(@“soapMessage%@”,soapMessage); NSString*urlString=@”http://l-156024038.testad.com:9000/HelloWorldService.svc"; NSURL*url=[NSURL URLWithString:urlString]; NSMutableURLRequest*theRequest=[[NSMutableURLRequest alloc]initWithURL:url]; NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]]; [请求设置值:@“gzip”用于HttpHeaderField:@“接受编码”]; [theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”]; [theRequest addValue:msgLength for HttpHeaderField:@“内容长度”]; [HttpHeaderField的请求附加值:@“l-15620438.testad.com:@“主机”]; [TheRequestAddValue:@“GetData”用于HttpHeaderField:@“SOAPAction”]; [请求设置值:@“基本”用于HttpHeaderField:@“授权”]; //theRequest=[NSMutableUrlRequestWithURL:url缓存策略:NSURLRequestReloadIgnoringLocal和RemoteCacheData timeoutInterval:45]; [TheRequestSetHttpMethod:@“获取”]; [TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding]; 连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self]; if(连接) { webData=[NSMutableData]; } 其他的 { NSLog(@“连接为空”); } } //此时,连接已设置,委托已设置为self,现在是使用连接委托方法的时候了。我们将使用四种方法: -(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应{ NSLog(@“响应值%@”,响应); } -(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据 { [webData:data]; NSLog(@“数据接收%@”,webData); } -(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误{ NSLog(@“连接错误%@”,错误); },iphone,ios,ipad,Iphone,Ios,Ipad,从上面的代码中,我无法从服务器获得响应 它总是调用错误的委托方法 @Sixten Otto Error with connection Error Domain=kCFErrorDomainCFNetwork Code=303“操作无法完成。(kCFErrorDomainCFNetwork Error 303。)”UserInfo=0x6a37870{nSerrorFailingUrlkey一些随意的谷歌搜索表明303错误代码可能是格式错误的HTTP请求/响应。我会尝试删除您的显式主机和内容长度
它总是调用错误的委托方法 @Sixten Otto Error with connection Error Domain=kCFErrorDomainCFNetwork Code=303“操作无法完成。(kCFErrorDomainCFNetwork Error 303。)”UserInfo=0x6a37870{nSerrorFailingUrlkey一些随意的谷歌搜索表明303错误代码可能是格式错误的HTTP请求/响应。我会尝试删除您的显式主机和内容长度(系统应该能够派生)然后继续运行,直到从服务器得到响应(这可能是某种故障),然后查看您的位置。
-(NSString *)getSoap{
NSString *getEnvelopeData = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
"<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">\n"
"<s:Header>\n"
"<a:Action s:mustUnderstand=\"1\">http://tempuri.org/IHelloWorldService/GetData</a:Action>\n"
"<a:MessageID>urn:uuid:e2c3af4e-5d69-4fd8-94bd-0e0f00976dad</a:MessageID>\n"
"<a:ReplyTo>\n"
"<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>\n"
"</a:ReplyTo>\n"
"</s:Header>\n"
"<s:Body>\n"
"<GetData xmlns=\"http://tempuri.org/\">\n"
"<value>0</value>\n"
"</GetData>\n"
"</s:Body>\n"
"</s:Envelope>\n"];
return getEnvelopeData;
}
-(void)loadSoapRequest{
NSString *soapMessage = [self getSoap];
NSLog(@"soapMessage %@",soapMessage);
NSString *urlString = @"http://l-156024038.testad.com:9000/HelloWorldService.svc";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[theRequest setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest addValue:@"l-156024038.testad.com" forHTTPHeaderField:@"Host"];
[theRequest addValue:@"GetData" forHTTPHeaderField:@"SOAPAction"];
[theRequest setValue:@"Basic " forHTTPHeaderField:@"Authorization"];
// theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:45];
[theRequest setHTTPMethod:@"GET"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [NSMutableData data];
}
else
{
NSLog(@"theConnection is NULL");
}
}
//At this point connection is setup and delegate is set to self, now is time to use connection delegate methods. Four methods that we gonna use:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"response Value %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
NSLog(@"Data Received %@",webData);
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"Error with connection %@",error);
}