次のコードを使用して、magento Webサービスを最初に呼び出します。これはログインです(このドキュメントを使用しました)
NSString *soapMessage = @" \
<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:Magento\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> \
<SOAP-ENV:Body> \
<ns1:login> \
<username xsi:type=\"xsd:string\">user</username> \
<apiKey xsi:type=\"xsd:string\">password</apiKey> \
</ns1:login> \
</SOAP-ENV:Body> \
</SOAP-ENV:Envelope>";
NSURL *url = [NSURL URLWithString:@"http://localhost/magentoPath/api/soap/?wsdl"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[request addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"localhost/magentoPath/" forHTTPHeaderField:@"SOAPAction"];
[request addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(connection){
self.webData = [NSMutableData data];
}
else
NSLog(@"theConnection is null");
後で、私が得た応答をログに記録する次のメソッドがあります。問題は、常にwsdlのコンテンツを取得することですが、magentoからセッションIDを取得する必要があります。私は何を間違えていますか?ありがとう!
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Done. received Bytes %d", [self.webData length]);
NSString *xml = [[NSString alloc] initWithBytes:[self.webData mutableBytes] length:[self.webData length] encoding:NSUTF8StringEncoding];
NSLog(xml);
}
ちなみに、リクエストxmlは、ログインが正しく機能するPHPのSoapClientからのものです。したがって、Magentoとは何の関係もありません。