iOS x-www-form-urlencoded格式传参

来源:互联网 发布:算法精解 java 编辑:程序博客网 时间:2024/06/06 00:18

    NSURL *url=[[NSURLalloc]initWithString:@"http://www.musems.com/index.php/survey"];

    

    NSMutableData *postBody=[NSMutableDatadata];

    [postBody appendData:[@"date=2016-01-11&time=04:46&location=LOCATION35&name=NAME&a1=1&a2=2&a3=2&a3_remark=a3_remark&a4=1&a5=2&a6=2&a7=1&a8=a8&a9=a9&password=musesurvey&activity_type=KA&product_name1=sdg&product_name2=dg"dataUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request=[[NSMutableURLRequestalloc]initWithURL:url

                                                            cachePolicy:NSURLRequestReloadIgnoringCacheData

                                                        timeoutInterval:20.0f];

    [requestsetHTTPMethod: @"POST"];

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

    [requestsetHTTPBody:postBody];

   NSError *error = nil;

   NSHTTPURLResponse* urlResponse = nil;

   NSData *responseData = [NSURLConnectionsendSynchronousRequest:request

                                                returningResponse:&urlResponse error:&error];

   NSString *result = [[NSStringalloc] initWithData:responseData

                                            encoding:NSUTF8StringEncoding];

   NSLog(@"结果:%@",result);


0 0
原创粉丝点击