nshttpurlresponse

How to use NSURLSession to determine if resource has changed?

只愿长相守 提交于 2019-12-28 13:58:13
问题 I'm using NSURLSession to request a JSON resource from an HTTP server. The server uses Cache-Control to limit the time the resource is cached on clients. This works great, but I'd also like to cache a deserialized JSON object in memory as it is accessed quite often, while continuing to leverage the HTTP caching mechanisms built into NSURLSession. I'm thinking I can save a few HTTP response headers: Content-MD5 , Etag , and Last-Modified along with the deserialized JSON object (I'm using those

response expectedContentLength return -1

陌路散爱 提交于 2019-12-28 03:03:08
问题 Hello i need to create a progressView when i load data from my webservice. Actually the expectedContentLength alway return -1. After look lots of similary problem it looks like my webservice never send the Content-Length:. Then i check with CURL and here is the result : < HTTP/1.1 200 OK < Date: Thu, 21 Jun 2012 10:04:39 GMT < Server: Apache/2.2.16 (Debian) < X-Powered-By: PHP/5.3.3-7+squeeze9 < cache-control: no-cache < Vary: Accept-Encoding < Content-Type: text/html; charset=UTF-8 < Content

Alamofire, Swift 2.0, SwiftyJSON: Parse response body as JSON

早过忘川 提交于 2019-12-25 03:35:36
问题 I have successfully completed a POST request to server and I am trying to parse the response JSON but I have been unsuccessful. Alamofire.request(.POST, ServerConfig.ADD_SELLER_URL, parameters: sellerJSON, encoding: .JSON, headers: nil) .responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in print(responseRequest!.URL) print(responseResponse) print(responseResult) let json = JSON(responseResponse!) print(json) }) I am using SwiftyJSON for JSON parsing. Here is

Swift: Unable to add .prettyPrinted format String to forHTTPHeaderField

為{幸葍}努か 提交于 2019-12-24 14:19:00
问题 By continuing from this question , I am trying to convert [String : Any] into String and then passing that String into forHTTPHeaderField Attempt 1: Without Pretty let encoder = JSONEncoder() if let json = try? encoder.encode(jsonDict) { convertedString = String(data: json, encoding: .utf8)! } print("JsonStringFormat ", convertedString ) let url = NSURL(string: getMenuURL) let request = NSMutableURLRequest(url: url! as URL) request.setValue(convertedString, forHTTPHeaderField: "SessionInfo")

NSHTTPURLResponse different on iPhone 5 vs 5s

▼魔方 西西 提交于 2019-12-11 04:49:16
问题 This is officially the weirdest thing I've ever seen. I have an iPhone 5 and an iPhone 5s, both on iOS 7.1.2, completely clean. I run the following code: NSString *userAgent = @"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"; NSURL *url = [NSURL URLWithString: deviceString]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url]; [request setValue:userAgent forHTTPHeaderField:@"User

Get cookies from NSHTTPURLResponse

流过昼夜 提交于 2019-11-29 04:16:49
I've an extremely weird problem, I'm requesting a URL and I want to get the cookies from it, I've used this way to get the cookies: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; NSDictionary *fields = [HTTPResponse allHeaderFields]; NSString *cookie = [fields valueForKey:"Set-Cookie"]; } BUT the cookies is not complete, there is some field is missing, I've checked it on PostMan, all the cookies is there. I've used also this method when initiating the NSURLRequest . [request

How to use NSURLSession to determine if resource has changed?

依然范特西╮ 提交于 2019-11-28 09:34:13
I'm using NSURLSession to request a JSON resource from an HTTP server. The server uses Cache-Control to limit the time the resource is cached on clients. This works great, but I'd also like to cache a deserialized JSON object in memory as it is accessed quite often, while continuing to leverage the HTTP caching mechanisms built into NSURLSession. I'm thinking I can save a few HTTP response headers: Content-MD5 , Etag , and Last-Modified along with the deserialized JSON object (I'm using those 3 fields since I've noticed not all HTTP servers return Content-MD5 , otherwise that'd be sufficient

Get cookies from NSHTTPURLResponse

谁都会走 提交于 2019-11-27 18:14:28
问题 I've an extremely weird problem, I'm requesting a URL and I want to get the cookies from it, I've used this way to get the cookies: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; NSDictionary *fields = [HTTPResponse allHeaderFields]; NSString *cookie = [fields valueForKey:"Set-Cookie"]; } BUT the cookies is not complete, there is some field is missing, I've checked it on PostMan,

response expectedContentLength return -1

旧城冷巷雨未停 提交于 2019-11-27 09:10:05
Hello i need to create a progressView when i load data from my webservice. Actually the expectedContentLength alway return -1. After look lots of similary problem it looks like my webservice never send the Content-Length:. Then i check with CURL and here is the result : < HTTP/1.1 200 OK < Date: Thu, 21 Jun 2012 10:04:39 GMT < Server: Apache/2.2.16 (Debian) < X-Powered-By: PHP/5.3.3-7+squeeze9 < cache-control: no-cache < Vary: Accept-Encoding < Content-Type: text/html; charset=UTF-8 < Content-Length: 3239 < Connection: Keep-Alive < Set-Cookie: PHPSESSID=u4o4i9dofdgnkfmtnf163635j6; path=/ and