代码之家  ›  专栏  ›  技术社区  ›  iDevZilla

带xml头的iPhone HTTPS帖子

  •  0
  • iDevZilla  · 技术社区  · 16 年前

    用身体我会做这样的事

    request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:CACHE_POLICY timeoutInterval:TIMEOUT_INTERVAL];
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
        [request setHTTPBody:postData];
    connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    

    但这不适用于标题,有人知道怎么做吗? XML是这样的

    <request>
    <code1>666</code1 >
    <code2>656</code2 >
    <code3>767</code3 >
    </request >
    

    谢谢。

    2 回复  |  直到 16 年前
        1
  •  0
  •   Brad The App Guy    16 年前
    [request setValue:@"<request><code1>666</code1 ><code2>656</code2 ><code3>767</code3 ></request >" forHTTPHeaderField:@"Your header field name?"];
    
        2
  •  0
  •   Adam    16 年前

    NSMutableString *urlString = [NSMutableString string];
    [urlString append:@"http://wahtever.com?something=something"];
    [urlString append:@"&data="];
    [urlString append:[@"<request>...etc</request>" stringByAddingPercentEscapesUsingEncoding:UTF8StringEncoding];
    
    NSURL *url = [NSURL URLwithString:urlString];
    request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:CACHE_POLICY timeoutInterval:TIMEOUT_INTERVAL];