NSMutableURLRequest 访问web html

//访问web文件 html文件

/*

 NSMutableURLRequest访问web html

 */


-(void)getHtmlMethod

{

    

    NSString *post = nil;  

    post = [[NSString alloc] initWithFormat:@"message=%@",@"hello,world."];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];  

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

 

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];  

    [request setURL:[NSURL URLWithString:@"http://x.x.x.x:8080/PlaceNaviServer/index.jsp"]];  

    [request setHTTPMethod:@"POST"]; 

    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];  

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

    [request setHTTPBody:postData];  

    //[NSURLConnection connectionWithRequest:request delegate:self ];  

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    NSLog(@"returnData = %@",returnData);

    [post release];


}


阅读更多
文章标签: web html
上一篇NSMutableURLRequest 发送同步请求get方法
下一篇c++
想对作者说点什么? 我来说一句

NSMutableURLRequest

2015年04月08日 227KB 下载

没有更多推荐了,返回首页

关闭
关闭