• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: HEAD request using NSURLConnection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HEAD request using NSURLConnection


  • Subject: Re: HEAD request using NSURLConnection
  • From: Daryn <email@hidden>
  • Date: Fri, 23 Jan 2004 00:51:45 -0600

Solely based on your symptoms, I'd bet a doughnut that if you sniffed
the payload of the requests, NSURL is using "Connection: keep-alive".
NSURL is probably too ignorant to properly handle HEAD request. It's
waiting for the specified Content-length of bytes that are not going to
be returned. Stalemate results until either NSURL times out, or the
remote server closes the connection due to inactivity.

Try invoking:
[request setValue:@"close" forHTTPHeaderField:@"Connection"]

I hope that helps!

On Jan 22, 2004, at 6:29 PM, Daniel Miao wrote:

> Hi,
>
> I have been trying to get the content length of a URL using an HTTP
> HEAD request.
>
> Here is my code snippet:
>
> NSMutableURLRequest *request = [NSMutableURLRequest
> requestWithURL:aURL
> cachePolicy:NSURLRequestReloadIgnoringCacheData
> timeoutInterval:30.0];
>
> [request setHTTPMethod:@"HEAD"];
>
> NSURLResponse *response = [[NSURLResponse alloc] init];
> NSError *error = [[NSError alloc] init];
>
> [NSURLConnection sendSynchronousRequest:request
> returningResponse:&response error:&error];
>
> long long dataLength = [response expectedContentLength];
>
>
> Eventually, the call to [NSURLConnection sendSynchronousRequest:]
> returns, but the problem is that there is a long delay. The first URL
> I tried was a file on my local machine served up by apache. The delay
> for that request was about 18 seconds. The second URL pointed to
> google (http://www.google.com/logos/lunarnewyear04.gif). That took
> about 4 minutes.
>
> Watching the packets, it seems that the HTTP request and response get
> sent and returned right away, but the client does not close the
> connection after receiving the header. Maybe NSURLConnection is
> expecting to receive actual body data before closing or something.
> I'm not sure. In the end, the call to [NSURLConnection
> sendSynchronousRequest: ] eventually returns when the _server_ closes
> the connection (by sending a FIN packet). This happens in
> asynchronous mode of NSURLConnection as well, when using a delegate.
>
> So has anyone encountered this issue before? Any help would be
> appreciated.
>
> Thanks!
>
> Daniel
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: HEAD request using NSURLConnection
      • From: Daniel Miao <email@hidden>
References: 
 >HEAD request using NSURLConnection (From: Daniel Miao <email@hidden>)

  • Prev by Date: Multiple document models.
  • Next by Date: Re: NSTask Memory Problems
  • Previous by thread: HEAD request using NSURLConnection
  • Next by thread: Re: HEAD request using NSURLConnection
  • Index(es):
    • Date
    • Thread