0

iPhone で特定の URL から簡単な XML 呼び出しを行いたいのですが、呼び出し時に毎回更新された結果が得られないため、既に URL をチェックインしましたが、実際の結果が得られません。

聞くのは.mコントローラーコードです

//This is SOAP calling
NSString *postString = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    "<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/\">\n"
    "<soap:Body>\n"
    "<GetCountries xmlns=\"http://www.webserviceX.NET\"/>\n"
    "</soap:Body>\n"
    "</soap:Envelope>";


//this is calling from URL wia above SOAP    
    dataWebService = [[NSMutableData data] retain];

    NSURL *tempURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.webservicex.net/country.asmx"]];
    NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:tempURL] retain];
    NSString *postLength =  [NSString stringWithFormat:@"%d", [postString length]];
    [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"http://www.webserviceX.NET/GetCountries" forHTTPHeaderField:@"SOAPAction"];
    [request addValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection * myConnection = [NSURLConnection connectionWithRequest:request delegate:self];
    [myConnection start];
    NSLog(@"%@Testing ",myConnection);
    [request release];

前もって感謝します

4

2 に答える 2

1

から任意の PHP スクリプトを呼び出すことができますNSURLConnection。これを行う方法の例を次に示します。

PHP

<?php

    print json_encode(array('MyKey' => 'value123'));
?>

Objective-C

NSData *myReceivedData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://myurl/path/to/api"]]];
NSError *jsonParseError = nil;
NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:myReceivedData options:0 error:&jsonParseError];

if (jsonParseError == nil) {
    NSLog(@"Value of MyKey: %@", [jsonObj objectForKey:@"MyKey"]);
}
else {
    NSLog(@"JSON Parse error: %@", jsonParseError);
}

同期要求を、非同期呼び出しの委任を使用するように自由に変更してください。

于 2013-01-22T04:44:25.833 に答える
0

これに対する解決策は、あなたの都合次第です。つまり、Web サービスは JSON 形式または XML 形式であり、それに応じて解析し、応答を使用できます。

于 2013-01-22T05:07:35.517 に答える