get 和post 方式请求数据
get 和post 方式請(qǐng)求數(shù)據(jù)的時(shí)候,只想說一句話,別忘了對(duì)NSMutableData *a 也就是用來接受數(shù)據(jù)的中間實(shí)例進(jìn)行初始化........
get 異步請(qǐng)求網(wǎng)絡(luò)數(shù)據(jù)的步驟
? NSURL *url = [[NSURL alloc] initWithString:@"http://f.hiphotos.baidu.com/image/w%3D2048/sign=2f72d721bb12c8fcb4f3f1cdc83b9345/ac4bd11373f082020756343e49fbfbedaa641bee.jpg"];
??? NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15];
??? NSURLConnection *connect = [[NSURLConnection alloc] initWithRequest:request delegate:self];
??? [connect release];
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)respons
{
??? [self.aview setProgress:0 animated:YES];
??? self.a = [respons expectedContentLength];
??? [self.receiverData setLength:0];
?? ?
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
??? [self.receiverData appendData:data];
??? float b = [self.receiverData length]/self.a;
??? [self.aview setProgress:b animated:YES];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
?
??? self.imageView.image? = [UIImage imageWithData:self.receiverData];
?? ?
}
同步
??? NSURL *url = [[NSURL alloc] initWithString:@"http://f.hiphotos.baidu.com/image/w%3D2048/sign=2f72d721bb12c8fcb4f3f1cdc83b9345/ac4bd11373f082020756343e49fbfbedaa641bee.jpg"];
??? NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
??? NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
??? UIImage *image = [UIImage imageWithData:data];
??? self.imageView.image = image;
轉(zhuǎn)載于:https://www.cnblogs.com/xukunhenwuliao/p/3576251.html
總結(jié)
以上是生活随笔為你收集整理的get 和post 方式请求数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: asp.net防止刷新时重复提交
- 下一篇: ASP.NET动态的修改主题