美文网首页
iOS关于xml的post请求

iOS关于xml的post请求

作者: Appstore_花木源 | 来源:发表于2017-08-25 16:52 被阅读76次

1.采用HTTPS方式访问

2.请求采用POST方式

3.提交和返回结果采用XML格式

NSString *xml = @"<xml><a>aaaaa</a><b>bbbbb</b></xml>" ; //xml格式

NSString *url =@"https://api.amob.com";

NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];

[request setHTTPMethod:@"POST"];

[request setHTTPBody:[xml dataUsingEncoding:NSUTF8StringEncoding]];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

//设置返回数据格式

operation.responseSerializer= [AFHTTPResponseSerializerserializer];

//请求

operation.securityPolicy.validatesDomainName=NO;//关键语句1

operation.securityPolicy.allowInvalidCertificates=YES;//关键语句2

[operationsetCompletionBlockWithSuccess:^(AFHTTPRequestOperation*_Nonnulloperation,id_NonnullresponseObject) {

NSString*result = [[NSStringalloc]initWithData:responseObjectencoding:NSUTF8StringEncoding];

NSLog(@"AFN--成功--结果:%@----返回数据%@", result, responseObject);

}failure:^(AFHTTPRequestOperation*_Nonnulloperation,NSError*_Nonnullerror) {

NSLog(@"AFN--失败--%@", error.localizedDescription);

}];

[operationstart];

相关文章

网友评论

      本文标题:iOS关于xml的post请求

      本文链接:https://www.haomeiwen.com/subject/yktpdxtx.html