gpt4 book ai didi

iphone - 如何从 iOS 连接到 Web 服务(SOAP + DES)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:53:10 26 4
gpt4 key购买 nike

<分区>

我是 Xcode 的新手,我需要连接到 Web 服务 API (SOAP + DES),这意味着我必须先向服务器发送用户名、密码、 key 和 IV,然后才能获取 XML 文件,然后解析它。

是否有关于从 iPhone 连接到 Web 服务 API(SOAP + DES)的教程?

    -(IBAction)buttonClick:(id)sender
{
recordResults = NO;

NSString *soapMessage = [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:Header>"
"<CredentialSoapHeader xmlns=\"http://tempuri.org/\">"
"<userID>xxxxx</userID>"
"<Password>xxxx</Password>"
"</CredentialSoapHeader>"
"</soap:Header>"
"<soap:Body>"
"<GetNearUserByArticleLatLon xmlns=\"http://tempuri.org/\">"
"<strXML>"
"<XMLDATA>\n"
"<KeyWord></KeyWord>\n"
"<Lat>0</Lat>\n"
"<Lon>0</Lon>\n"
"<IP>219.71.65.55</IP>\n"
"<CurrentPage>1</CurrentPage>\n"
"<PageSize>10</PageSize>\n"
"</XMLDATA>\n"
"</strXML>"
"</GetNearUserByArticleLatLon>"
"</soap:Body>"
"</soap:Envelope>"];


NSLog(@"%@", soapMessage);

//http://www.xignite.com/services/GetRealQuote
NSURL *url = [NSURL URLWithString:@"http://api3.mmnears.com/API/api.asmx?op=GetNearUserByArticleLatLon"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://tempuri.org/GetNearUserByArticleLatLon" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];


NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
NSLog(@"theConnection = %@",theConnection);

if(theConnection)
{
webData = [[NSMutableData data] retain];
NSLog(@"WebData = %@",webData);

}
else
{
NSLog(@"theConnection is null");
}

}


-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
{
[webData setLength:0];
NSHTTPURLResponse * httpResponse;

httpResponse = (NSHTTPURLResponse *) response;

NSLog(@"HTTP error %zd", (ssize_t) httpResponse.statusCode);

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
{
[webData appendData:data];
NSLog(@"webdata: %@", data);

}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError*)error
{
NSLog(@"error with the connection");
[connection release];
[webData release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received bytes %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"xml %@",theXML);
[theXML release];

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com