分类: iOS平台
2013-03-01 22:55:20
iphone客户端调用:
1、get的方式:
- NSString *queryString =
- [NSString stringWithFormat:
- @“param=123%@“,
- ipAddress.text];
- NSURL *url = [NSURL URLWithString:queryString];
- NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
- [req addValue:@“text/xml; charset=utf-8” forHTTPHeaderField:@“Content-Type”];
- [req addValue:0 forHTTPHeaderField:@“Content-Length”];
- [req setHTTPMethod:@“GET”];
- [activityIndicator startAnimating];
- conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
- if (conn) {
- webData = [[NSMutableData data] retain];
- }
2、post的方式:
- NSString *postString =@"123";
- NSURL *url = [NSURL URLWithString:
- @“”];
- NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
- NSString *msgLength = [NSString stringWithFormat:@“%d”, [postString length]];
- [req addValue:@“application/x-www-form-urlencoded”
- forHTTPHeaderField:@“Content-Type”];
- [req addValue:msgLength forHTTPHeaderField:@“Content-Length”];
- [req setHTTPMethod:@“POST”];
- [req setHTTPBody: [postString dataUsingEncoding:NSUTF8StringEncoding]];
- [activityIndicator startAnimating];
- conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
- if (conn) {
- webData = [[NSMutableData data] retain];
- }