nsurlrequest

NSDate to RFC 2822 Date format

冷暖自知 提交于 2019-12-07 11:22:07
问题 Is there any efficient way to convert an NSDate to RFC 2822 Date format string ? I want to use this string to create an NSURLRequest and set the value of "If-Modified-Since" header field. 回答1: try to use an NSDateFormatter NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // maybe there exist a new-method now dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format NSString *dateString = [dateFormatter stringFromDate:myDate]; 回答2: Swift 3 let rfcDateFormat =

Does disk caching with NSURLRequest and NSURLConnection actually work on the iPhone?

ぐ巨炮叔叔 提交于 2019-12-07 07:30:50
问题 I have a UITableView whose cells contain custom ImageViews that asynchronously load the images from the internet. To load those images I use NSURLRequest and NSURLConnection which works fine. The only problem is that the images are not cached and therefore are downloaded every time they are used. I tried to set the cachePolicy of the NSURLRequest to "NSURLRequestReturnCacheDataElseLoad" with no effect. It seems from the last answer on link that disk caching is not supported with NSURLRequest

HTTPS POST from iPhone using NSURLConnection hangs for certain filesize range

不问归期 提交于 2019-12-07 05:32:07
问题 I'm using NSURLConnection to make an async HTTPS POST to our webservice to upload a jpg. It works fine most of the time. But when the post body is between 196609 and 196868 bytes (inclusive), the connection hangs after the file has been uploaded 100% (didSendBodyData tells me that it's 100% sent). Then after 5 minutes, the connection times out with the message "The network connection was lost." Larger and smaller filesizes work. I've tested this by capping the filesize of the file that I add

使用Swift读取Cookie内容

微笑、不失礼 提交于 2019-12-07 00:10:52
前言 一个http请求中,我们经常会涉及到Get请求的URL Param,POST请求的HTTP Body,Response Json,这些都是一个标准REST API标配的元素。 在一些安全验证的API中,通常会涉及到Cookie。当用户成功登陆后,服务器会在Response Header中写入一个Set-Cookie字段,用来标识用户已经登陆(授权)成功,客户端浏览器接收后会把这个Cookie字段保存在客户端本地。当客户端再次请求API时,就会在Request Header中带上这个Cookie值,告诉服务器:嗨,我已经授权过咯,我的cookie值是xxx,我现在要读取一些信息,请放行~ IOS中的网络请求 一个完整的网络请求,需要先确定Request URL,带上参数,然后发送Request,然后接收Response,处理Response Data。 在IOS中,分别对应如下: //Request URL NSURL //一个完整的Request对象 NSURLRequest //发送请求连接的主要操作者 NSURLConnection //包含返回数据的Response NSURLResponse 下面是一个简单的GET请求代码: let request = NSURLRequest(URL: NSURL(string: "http://devonios.com")!)

Downloading multiple files writes same data to all files

旧巷老猫 提交于 2019-12-06 21:25:29
Attempting to download multiple files from an XML feed. There are several Categories and each category has an unknown amount of images. I create a subdirectory for each category, no problem. When I try to download each file to the respective category, every file is written with the same data for every image there is in the feed. I guess my question is how can I download 1 file at a time to the corresponding directory without overwriting all of the images with the same data? -(void)parsingComplete:(XMLDataSource*)theParser { /* iterate through the Categories and create the sub-directory if it

HTTP Status Code 411 - Length Required

﹥>﹥吖頭↗ 提交于 2019-12-06 18:24:53
问题 I try to get data from server. I use NSURLConnectionDelegate, NSURLConnectionDataDelegate. There is code (Objective - C). -(void)sendRequest { NSURL* url = [[NSURL alloc] initWithString:@"http://SomeServer"]; NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; NSString* reqBody = [NSString stringWithFormat:@"<tag>Content</tag>"]; NSData* reqData = [reqBody dataUsingEncoding:NSUTF8StringEncoding]; NSInputStream* stream = [NSInputStream inputStreamWithData:reqData]; [request

NSURLRequest with caching not working

自闭症网瘾萝莉.ら 提交于 2019-12-06 16:40:09
问题 I am trying to cache my nsurlrequest data. Prior to this i was successfully downloading data from the server, ever since I tried to implement this cache its been making my application fall over. Im hoping someone can look at the code i have so far and help me to get it workig.. I think I have roughly 95% of it done. - (IBAction)setRequestString:(NSString *)string { //Set database address NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:29/"]; // imac

NSURLRequest setValue: forHTTPHeaderField:@“Authorization” not working

走远了吗. 提交于 2019-12-06 11:31:44
I try to make an authenticate call to the twitter API with the Application only Authentication API NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"Some App Name" forHTTPHeaderField:@"User-Agent"]; [request setValue:authValue forHTTPHeaderField:@"Authorization"]; [request setHTTPBody:[@"grant_type=client_credentials"

NSURLConnection not responding

独自空忆成欢 提交于 2019-12-06 08:09:53
问题 I'm trying to get some data from an URL, but for some reason, nothing happens when I do the following. Neither didReceiveResponse: , didReceiveData: , didFailWithError: or connectionDidFinishLoading: are reached, except when I add a timeout to my request by doing this: [request setTimeoutInterval:10.0] Here's what I'm doing : -(void)getConfigFromServer{ [self getContentAtURL:kUrlGetUser]; } //Va chercher le contenu à l'URL passée en paramètre - (void)getContentAtURL: (NSURL *)url {

How to add lowercase field to NSURLRequest header field?

情到浓时终转凉″ 提交于 2019-12-06 07:48:52
问题 I'm getting pretty frustrated figuring out how to add a lowercase header field to an NSMutableURLRequest. NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:MyURLString]]; [urlRequest setValue:@"aValue" forHTTPHeaderField:@"field"]; In the example above, "field" gets switched to "Field," since the header field names are case insensitive. I would think this shouldn't happen, but it does. The API I am working with is case sensitive, so my GET request is