iphoneweb服务应用程序

iphoneweb服务应用程序,iphone,ios,web-services,Iphone,Ios,Web Services,您好,我正在编写一个iphone应用程序,它可以与web服务进行通信,所以我有两个文本字段,程序需要读取第一个文本字段的值并发布web服务,然后在web服务响应之后,它需要写入第二个文本字段。但是在第二个文本字段中,它没有写任何东西。它在控制台上打印空值。为什么会变成这样? 谢谢 -(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil { self=[super initWithNibName:n

您好,我正在编写一个iphone应用程序,它可以与web服务进行通信,所以我有两个文本字段,程序需要读取第一个文本字段的值并发布web服务,然后在web服务响应之后,它需要写入第二个文本字段。但是在第二个文本字段中,它没有写任何东西。它在控制台上打印空值。为什么会变成这样? 谢谢

-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
nodeContent=[[NSMutableString alloc]init];
}
回归自我;
}
-(iAction)登录名:(id)发件人{
NSLog(@“密码文本:%@”,PASSWORD.text);
如果([password.text length]==0){
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“WebService”消息:@“在文本字段中提供数据”委托:无取消按钮:无其他按钮:无确定,无];
[警报显示];
[警报发布];
}
否则{
NSString*soapFormat=[NSString stringWithFormat:@“\n”
“\n”
“\n”
“\n”
“%@\n”
“\n”
“\n”
“\n”,密码.text];
NSLog(@“请求格式为%@”,soapFormat);
NSURL*locationOfWebService=[NSURL URLWithString:@”http://www.w3schools.com/webservices/tempconvert.asmx"];
NSLog(@“web url=%@”,位置WebService);
NSMutableURLRequest*theRequest=[[NSMutableURLRequest alloc]initWithURL:locationOfWebService];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapFormat length]];
[TheRequestAddValue:@“文本/xml”用于HttpHeaderField:@“内容类型”];
[请求附加值:@”http://tempuri.org/CelsiusToFahrenheitforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
//下面的编码用于通过网络发送数据
[TheRequestSetHttpBody:[soapFormat数据使用编码:NSUTF8StringEncoding];
NSURLConnection*connect=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
如果(连接){
webData=[[NSMutableData alloc]init];
startActivityIndicator;
}
否则{
NSLog(@“未建立连接”);
}
//[self-PerformsgueWithIdentifier:@“logindevam”发件人:self];
}
}
-(iAction)发送键盘:(id)发送程序{
[发送方辞职第一响应方];
}
-(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应
{
[webData setLength:0];
}
-(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据
{
[webData:data];
}
-(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误
{
NSLog(@“组件错误”);
[连接释放];
[网络数据发布];
}
-(无效)连接IDFinishLoading:(NSURLConnection*)连接
{
NSLog(@“完成。收到的字节数:%d”,[webData长度];
NSString*theXML=[[NSString alloc]initWithBytes:[webData可变字节]长度:[webData长度]编码:NSUTF8StringEncoding];
NSLog(@“%@”,XML);
xmlParser=[[NSXMLParser alloc]initWithData:webData];
[xmlParser setDelegate:self];
//[xmlParser setShouldResolveExternalEntities:是];
[xmlParser parse];
//  
[连接释放];
//[网络数据发布];
//[可结果的重新加载数据];
停止活动指示器;
}
//xml委托
-(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName属性:(NSDictionary*)attributeDict
{
}
-(void)解析器:(NSXMLParser*)解析器查找字符:(NSString*)字符串
{
[nodeContent appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName
{
if([elementName IseQualtString:@“CelsiUstofHarenHeitResult”]){
NSLog(@“nodeContent:%@”,nodeContent);//它变为null
最终数据=节点内容;
NSLog(@“finaldata:%@”,finaldata);//它变为空
NSLog(@“username.text:%@”,username.text);//它变为null
username.text=最终数据;
}
username.text=最终数据;
}
代码::

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

   NSLog(@"DONE. Received Bytes: %d", [webData length]);
   NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);

   theXML = [theXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
   theXML = [theXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
   theXML = [theXML stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];

   NSString *str, *result;
   result = [[[NSString alloc] initWithFormat:@""] autorelease];

   NSArray *array=[theXML componentsSeparatedByString:@"<CelsiusToFahrenheitResult>"];
   for(int i=1;i<[array count];i++)
   {
      str=[array objectAtIndex:i];

      NSRange ranfrom=[str rangeOfString:@"</CelsiusToFahrenheitResult>"];
      result =[str substringToIndex:ranfrom.location];
   }

   NSLog(@"\n -> %@", result);

   t2.text = result; // Your Second textfield

   [connection release];
}
-(void)连接dFinishLoading:(NSURLConnection*)连接{
NSLog(@“完成。收到的字节数:%d”,[webData长度];
NSString*theXML=[[NSString alloc]initWithBytes:[webData可变字节]长度:[webData长度]编码:NSUTF8StringEncoding];
NSLog(@“%@”,XML);
XML=[XML字符串通过替换字符串@的发生率@和字符串@来表示];
XML=[XML字符串通过替换字符串@”和“;”与字符串@”和“]的重复出现;
NSString*str,*结果;
结果=[[NSString alloc]initWithFormat:@”“]自动释放];
NSArray*array=[由字符串分隔的XML组件:@”“;

对于(int i=1;i)您需要提供更多详细信息。什么有效,什么无效?web服务被调用了吗?它返回了吗?它返回了预期的数据吗?什么代码将
null
打印到控制台?帮助我们帮助您。我在[link]中尝试了此代码哈?这如何回答我的任何问题?你已经发布了你的代码。现在你正在链接到其他代码。对不起,如果你不能向我们提供关于你的代码实际达到了什么程度以及问题所在的任何细节,没有人能帮到你多少忙。你能提供不需要XMLParser类的日志吗。
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

   NSLog(@"DONE. Received Bytes: %d", [webData length]);
   NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);

   theXML = [theXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
   theXML = [theXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
   theXML = [theXML stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];

   NSString *str, *result;
   result = [[[NSString alloc] initWithFormat:@""] autorelease];

   NSArray *array=[theXML componentsSeparatedByString:@"<CelsiusToFahrenheitResult>"];
   for(int i=1;i<[array count];i++)
   {
      str=[array objectAtIndex:i];

      NSRange ranfrom=[str rangeOfString:@"</CelsiusToFahrenheitResult>"];
      result =[str substringToIndex:ranfrom.location];
   }

   NSLog(@"\n -> %@", result);

   t2.text = result; // Your Second textfield

   [connection release];
}