Questions tagged [nshttpurlresponse]
50 questions
32
votes
3 answers
How to get the response data out of the NSHTTPURLResponse in the callback of AFJSONRequestOperation?
I have a situation where I need to access the raw response data for an AFJSONRequestOperation, from within the callback block which includes only NSHTTPURLResponse. I am able to get the statusCode from the NSHTTPURLResponse, but don't see any way to…

Todd Hopkinson
- 6,803
- 5
- 32
- 34
25
votes
6 answers
How to convert NSHTTPURLResponse to String in Swift
I would like to convert my response from the NSHTTPURLResponse type to String:
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) -> Void in
println("Response: \(response)")
var responseText:…

Karl Ivar
- 287
- 1
- 3
- 6
19
votes
5 answers
How can I access the "Content-Type" header of an NSHTTPURLResponse?
Here's my naive first pass code:
var httpUrlResponse: NSHTTPURLResponse? // = (...get from server...)
let contentType = httpUrlResponse?.allHeaderFields["Content-Type"]
I've tried various derivations of this code, but I keep getting compiler…

Daniel
- 8,794
- 4
- 48
- 71
11
votes
10 answers
HTTPURLResponse allHeaderFields Swift 3 Capitalisation
Converting to Swift 3 I noticed a strange bug occur reading a header field from HTTPURLResponse.
let id = httpResponse.allHeaderFields["eTag"] as? String
no longer worked.
I printed out the all headers dictionary and all my header keys seem to be…

Mark Bridges
- 8,228
- 4
- 50
- 65
10
votes
5 answers
Get cookies from NSHTTPURLResponse
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…

Scar
- 3,460
- 3
- 26
- 51
5
votes
4 answers
dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPURLResponse
I wrote a Swift App with Xcode6 Beta 2 that does some networking using CFNetwork classes such as NSURLRequest and NSHTTPURLResponse.
The App works just fine with iOS 8, still, when I try to run it on an iOS 7 device or in the simulator running iOS…

Patrick
- 137
- 1
- 8
5
votes
2 answers
How do you get the status code from dataTaskWithURL's NSURLResponse?
I am performing a simple get request with Apple's NSURLSession#dataTaskWithURL method
[[mySession dataTaskWithURL:myUrl completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// fancy code goes here...
}] resume];
If I…

patrick
- 9,290
- 13
- 61
- 112
3
votes
2 answers
How to use NSURLSession to determine if resource has changed?
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…

Doug Richardson
- 10,483
- 6
- 51
- 77
3
votes
1 answer
Modify headers in NSHTTPURLResponse
Is it possible to modify a header on a NSHTTPURLResponse without using the method
initWithURL:statusCode:HTTPVersion:headerFields:
to create a new customized NSHTTPURLResponse

hd143
- 39
- 2
- 6
3
votes
2 answers
response expectedContentLength return -1
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…

Damien Locque
- 1,810
- 2
- 20
- 42
2
votes
1 answer
Problem parsing JSON data from server Swift
I'm trying to parse data from the server, but I get this error:
failure(Swift.DecodingError.typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary…

Edward Pizzurro
- 575
- 4
- 15
2
votes
1 answer
HTTPURLResponse.localizedString(forStatusCode:) not in development language
I am making an iOS app, and I have this problem.
My app most be only in Spanish, so i changed the development language (in the hard way, changing the developmentRegion = es; inside the the project.pbxproj and changing the…
2
votes
3 answers
How to handle 500 http errors
I am trying to access the custom server response body for 500 errors in class HTTPURLResponse (URLResponse) using URLSession.shared.dataTask function. I can only have access to statusCode and allHeaderFields but it doesn't seem to help.
The…

Andrei F
- 4,205
- 9
- 35
- 66
2
votes
2 answers
How to get HTTP protocol version from a given NSHTTPURLResponse?
From NSHTTPURLResponse documentation, I did not find a way to get the HTTP version (i.e. "HTTP/1.1" or "HTTP/1.0").
HTTP header fields are available through all Header Fields property, however the HTTP protocol version is not given inside the…

AmitW
- 798
- 8
- 11
2
votes
1 answer
Where's the response data from a 500 error in NSURLSession?
I have the following Swift code in my iOS app:
session?.dataTaskWithRequest(urlRequest, completionHandler: { (data, response, error) -> Void in
if let httpResponse = response as? NSHTTPURLResponse {
var dataString:String?
if data…

dumbledad
- 16,305
- 23
- 120
- 273