关于ios iphone 调用asp.net webservice 的使用

-(void)testPOST

{

    NSError *error;

    NSURLResponse *theResponse;

    

    NSURL *url = [NSURL URLWithString:

                  @"http://192.168.0.2:12/app/post.asmx"];

    NSMutableURLRequest *req = [NSMutableURLRequestrequestWithURL:url];

    //NSString *msgLength = [NSString stringWithFormat:@"%d", [postString length]];

    [req addValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];

    [req setHTTPMethod:@"POST"];

    //[req setValue:@"0" forHTTPHeaderField:@"StarIndex"];

    //[req setValue:@"10" forHTTPHeaderField:@"EndIndex"];

    //[req setHTTPBody: [postString dataUsingEncoding:NSUTF8StringEncoding]];

    NSString *postUrl=@"StarIndex=0&EndIndex=10";  

    [req setHTTPBody:[postUrl dataUsingEncoding:NSUTF8StringEncoding]];

    NSData *data=[NSURLConnectionsendSynchronousRequest:req returningResponse:&theResponse error:&error];

    NSLog(@"POSTDATA %@",[[NSStringalloc] initWithData:data encoding:NSUTF8StringEncoding]);    

    

}

-(void)testGET

{

    NSString *queryString =

    [NSStringstringWithFormat:

     @"http://192.168.0.2:12/app/get.asmx/getlist&StarIndex=0&EndIndex=10"];

    NSURL *url = [NSURL URLWithString:queryString];

    NSMutableURLRequest *req = [NSMutableURLRequestrequestWithURL:url];

    [req addValue:@"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];

    [req addValue:0forHTTPHeaderField:@"Content-Length"];

    [req setHTTPMethod:@"GET"];

    

    NSError *error;

    NSURLResponse *theResponse;

    NSData *data=[NSURLConnectionsendSynchronousRequest:req returningResponse:&theResponse error:&error];

    NSLog(@"GETDATA %@",[[NSStringalloc] initWithData:data encoding:NSUTF8StringEncoding]);

    

}

你可能感兴趣的:(webservice)