加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

使用.net Web服务从iphone调用http post URL

发布时间:2020-12-14 21:17:35 所属栏目:资源 来源:网络整理
导读:当我点击按钮时,我需要从我的iPhone拨打网址. url从UITextField获取一个值作为参数,它也使用POST方法来调用webservice.我如何使用我的iPhone中的URL.我用GET方法做了同样的事情.但为此我创建了一个带有textfield值的url字符串.它不能用于POST.所以我为此做了
当我点击按钮时,我需要从我的iPhone拨打网址.

url从UITextField获取一个值作为参数,它也使用POST方法来调用webservice.我如何使用我的iPhone中的URL.我用GET方法做了同样的事情.但为此我创建了一个带有textfield值的url字符串.它不能用于POST.所以我为此做了什么.是否有任何示例代码..此外,Web服务是“.asmx”类型.这就是我所做的…..

-(IBAction)loginButtonPressed:(id)sender{
NSString *post =[NSString stringWithFormat:@"name=myUserName&pass=myPassword"];
NSLog(post);        

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:@"http://192.168.50.194:9989/webservice1.asmx?op=LoginAuthentication"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];


NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(data);

}

我得到的错误是

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to process request. ---&gt; Data at the root level is invalid. Line 1,position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

请帮帮我.!!!

谢谢,
世斌

解决方法

您可以使用以下内容将HTTP方法设置为使用POST而不是默认GET:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL];
[request setHTTPMethod:@"POST"];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读