0

ユーザーを登録できる Web ページに XML 形式のデータを送信しようとしています。

私は2つの方法を試しましたが、両方の方法でデータを取得しました。

方法-1

    NSString *urlString = @"http://****.com/iphone/csi/register.php?choice=register";
    NSURL *url = [NSURL URLWithString: urlString];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url];
    [request setHTTPMethod: @"POST"];
    [request setValue: @"text/xml" forHTTPHeaderField: @"Content-Type"];

    NSMutableData *highScoreData = [NSMutableData data];
    [highScoreData appendData: [[NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"] dataUsingEncoding: NSUTF8StringEncoding]];
    [highScoreData appendData: [[NSString stringWithFormat: @"<user_name>%@</user_name", @"test"] dataUsingEncoding: NSUTF8StringEncoding]];
    [highScoreData appendData: [[NSString stringWithFormat: @"<password>%@</password>", @"test"] dataUsingEncoding: NSUTF8StringEncoding]];
    [highScoreData appendData: [[NSString stringWithFormat: @"</xml>"] dataUsingEncoding: NSUTF8StringEncoding]];
    [request setHTTPBody: highScoreData];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest: request
                                                                delegate: self];

方法-2

    NSString * xmlString = @"<test><message>Hello</message></test>";        
    NSURL * serviceUrl = [NSURL URLWithString:@"http://demos4clients.com/iphone/csi/register.php?choice=register"];
    NSMutableURLRequest * serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl];
    [serviceRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
    [serviceRequest setHTTPMethod:@"POST"];
    [serviceRequest setHTTPBody:[xmlString dataUsingEncoding:NSASCIIStringEncoding]];

    NSURLResponse * serviceResponse;
    NSError * serviceError;
    serviceResponse = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:&serviceResponse error:&serviceError];

このエラーの理由を見つけるにはどうすればよいですか?

4

0 に答える 0