zoukankan      html  css  js  c++  java
  • 关于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]);

        

    }

  • 相关阅读:
    第七届河南省赛F.Turing equation(模拟)
    第八届acm省赛 A挑战密室(模拟)
    展开字符串(dfs)
    排名(水题)
    Identity Card(水题)
    Dropping Balls (二叉树+思维)
    SQL学习——IN运算符
    SQL学习——BETWEEN运算符
    SQL学习——LIKE运算符
    【数字图像处理】灰度转换算法
  • 原文地址:https://www.cnblogs.com/Rampage/p/2494689.html
Copyright © 2011-2022 走看看