1 ) SOAP:基于XML的一種協(xié)議規(guī)范,用來描述傳遞信息的格式(接口調(diào)用要遵循此格式)
2 ) WSDL:描述如何調(diào)用或訪問具體的接口
3 ) UDDI:管理,查詢webService
注:調(diào)用接口最重要的就是要遵循SOAP協(xié)議格式
SOAP協(xié)議一般格式
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www-w3-org/2001/XMLSchema-instance" xmlns:xsd="http://www-w3-org/2001/XMLSchema" xmlns:soap="http://schemas-xmlsoap-org/soap/envelope/">
<soap:Body>
//Body之間是需要調(diào)用的方法以及參數(shù)列表
</soap:Body>
</soap:Envelope>
發(fā)送soap請求:
//soap格式要和接口吻合
NSString *str = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\
<soap:Body>\
<要調(diào)用的方法名 xmlns=\"命名空間\">\
<參數(shù)>參數(shù)值</參數(shù)>\
...
</要調(diào)用的方法名>\
</soap:Body>\
</soap:Envelope>"];
NSURL *url = [NSURL URLWithString:@"接口網(wǎng)址"];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
NSString *length = [NSString stringWithFormat:@"%lu",(unsigned long)[str length]];
[request setHTTPMethod:@"POST"];
[request addValue:@"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];
[request addValue:length forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:[str dataUsingEncoding:NSUTF8StringEncoding]]; // body內(nèi)容
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//請求完成是xml格式的,可以先不處理,用字符串接收查看一下
NSString *resultStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (error) {
NSLog(@"---失敗----%@", error.localizedDescription);
}
}];
[task resume]; }