Questions tagged [nshttpurlresponse]
50 questions
2
votes
0 answers
WKWebview loosing login cookie
I currently have an issue with hybrid application that uses an WKWebView to display a webpage.
After the application restarts and creates a new session / WKWebWiew, a new login cookie is given to the WKWebView from the webservice. This works fine in…

oscar
- 647
- 1
- 5
- 17
2
votes
3 answers
Provide HTTPVersion to NSHTTPURLResponse
My application uses custom NSURLProtocol subclass. I need to substitute NSHTTPURLResponse with my copy, modifying some of the headers fields. So, I create new NSHTTPURLResponse instance, like that:
@implementation NSHTTPURLResponse (CocoaFix)
-…

Borys Verebskyi
- 4,160
- 6
- 28
- 42
2
votes
2 answers
NSHTTPURLResponse Status Code 200 in Airplane Mode
I have an interesting problem: when my device is in Airplane Mode, the HTTP Status Code that the NSHHTPURLResponse provides is 200 "OK".
Shouldn't it fail with an error, or at least not respond that it has a valid connection with code 200?
Here is a…

Jake Chasan
- 6,290
- 9
- 44
- 90
2
votes
1 answer
NSHTTPURLResponse's initWithURL method crashes if we set header "Content-Length"
Here's some code, where we set up an NSHTTPURLResponse object:
NSString * data = @"response successful";
NSUInteger length = [data length];
NSDictionary * headersDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber…

jianhua
- 1,011
- 1
- 12
- 28
1
vote
1 answer
How can I call HttpUrlConnection disconnect()
My code sends HttpConnection and then tries to use either connection.getInputStream() or connection.getErrorStream() to deserialize response.
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
BufferedReader in = new…

B. Wasnie
- 541
- 1
- 4
- 12
1
vote
2 answers
Swift: Unable to add .prettyPrinted format String to forHTTPHeaderField
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) {
…

McDonal_11
- 3,935
- 6
- 24
- 55
1
vote
1 answer
iOS HttpUrlResponse Header Field Case Sensitivity
When attempting to get the headers from an HttpUrlResponse, I am finding the iOS simulator is case-insensitive and a real device is case-sensitive.
The web service returns an HTTP header "Grandmas-Cookies: XXXX"
When the header key has uppercase…

Adam
- 4,590
- 10
- 51
- 84
1
vote
1 answer
How Can I Return `nil` for HTTPURLResponse?
I have the following method which I used for retrieving a cookie from response headers:
internal static func cookie(from response: HTTPURLResponse) -> HTTPCookie? {
guard let url = response.url else { return nil }
guard let headerFields =…

Nick Kohrn
- 5,779
- 3
- 29
- 49
1
vote
1 answer
What Format Do HTTP Headers Return As?
I have been trying to unit test HTTP response headers. I need to receive a cookie from the headers. I get two Set-Cookie headers back, but I need one for authentication. The returned headers are:
HTTP/1.1 200 OK
Server: Cowboy
Connection:…

Nick Kohrn
- 5,779
- 3
- 29
- 49
1
vote
0 answers
Duplicate Set-Cookie Headers from HTTPURLResponse
I am hitting an API to get a cookie for authenticating subsequent requests. I need to get the cookie from this collection of response headers:
{
"Server": "Cowboy",
"Connection": "close",
"Set-Cookie":…

Nick Kohrn
- 5,779
- 3
- 29
- 49
1
vote
3 answers
NSHTTPCookieStorage for same URL but different users
May be this is a dumb question, but I want to store cookies for same url but different for usernames. How can this be achieved using NSHTTPCookieStorage ? This is how I store cookies from response.
NSHTTPURLResponse *httpResponse =…

Deepak Sharma
- 5,577
- 7
- 55
- 131
1
vote
1 answer
Cast from 'NSData' to unrelated type 'NSHTTPURLResponse' always fails
I have this code :
let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
guard let response = data else {
print("Error: did not receive data")
return
…

Dani Turc
- 39
- 2
- 11
1
vote
1 answer
Getting file size with NSURLConnection is very slow
I try to get the filesize of a file stored on a server.
I manage to do, but it takes as long as I would download it.
I assume it will download the file to evaluate the size.
Is there a faster way to get the file size?
func…

mcfly soft
- 11,289
- 26
- 98
- 202
1
vote
0 answers
Enum/Constants defined for NSHTTPURLResponse statusCode?
Does Foundation (or other 1st party framework) have enum/constants for the NSHTTPURLResponse HTTP statusCode values? For example, something like:
NSInteger kHTTPStatusCodeForbidden = 403;
Searched through the docs, but couldn't find anything.

ospr
- 1,650
- 2
- 17
- 21
1
vote
1 answer
NSHTTPURLResponse different on iPhone 5 vs 5s
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)…

JeffN
- 1,575
- 15
- 26