use*_*195 1 iphone iphone-sdk-3.0
我正在为I-phone 3.0搜索HTTP示例.我正在使用基于http的协议来同步两个数据库(即客户端和服务器)使用POST和GET.So我将使用POST向服暗示会使用什么类型的框架?
我将假设您有兴趣实现一些普通的旧HTTP客户端代码.请求网页等
我使用NSURL来处理我的HTTP请求.这很简单.您可以在NSURL类参考上阅读所有相关内容,但这里有一段示例代码:
// set up your request
NSURL * url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
NSURLRequest * request = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
// create your connection with your request and a delegate (in this case
// the object making the request)
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)
您只需要实现一些委托方法来处理数据响应
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLResponse*)response
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1958 次 |
| 最近记录: |