 |
 |
Downloading off a .mac homepage
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status:
Offline
|
|
I am trying to download a file off a .mac account. I wrote a small program like this:
[socket connectToHost:someHost port:80];
[socket writeString:@"GET %@ HTTP/1.1\r\n\r\n", theDirectory];
while ([socket isConnected])
[socket readData:data];
NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);
This works for basically every web page. However, on a .mac page, i just get something like this:
HTTP/1.1 403 Forbidden
Date: Tue, 22 Jul 2003 05:09:41 GMT
Content-Length: 257
Content-Type: text/html
Server: NetCache (NetApp/5.2.1R2D2)
<HTML>
<HEAD><TITLE>403 Forbidden</TITLE></HEAD>
<BODY>
<H1>Forbidden</H1>
<H4>
You were denied access because:<P>
Access denied by access control list.
</H4>
<HR>
</BODY>
</HTML>
But if i type the address into a browser, the page will come up fine. It isn't password protected but other parts of the site are. How can I fix this...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
Just an idea since I don't know much about this, but maybe you should add a fake user agent string. The server may be rejecting what it thinks are webcrawlers or non-browser clients.
|
|
|
| |
|
|
|
 |
|
 |
|
Banned
Join Date: Apr 2002
Location: -
Status:
Offline
|
|
Originally posted by seppak:
I am trying to download a file off a .mac account. I wrote a small program like this:This works for basically every web page. However, on a .mac page, i just get something like this:
But if i type the address into a browser, the page will come up fine. It isn't password protected but other parts of the site are. How can I fix this...
HTTP is pretty tricky.
Use CURLHandle instead (or NSURLHandle)
http://curlhandle.sf.net
it comes with a nice example application.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Either that or you could use the new stuff in Foundation as of Safari 1.0 (NSURL*)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
You are being refused because that is an invalid HTTP/1.1 request. All HTTP/1.1 requests MUST have a Host: header in the request, or send an absolute URI in the request. Sending an absolute URI in the request however, should, as of HTTP/1.1, only be used when talking directly to a proxy (transparent proxies don't count in this case).
Your request should look something like this:
GET /steve/ HTTP/1.1
Host: homepage.mac.com
You will probably be best off doing this stuff via the Cocoa classes mentioned before, mainly NSURLHandle.
- proton
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status:
Offline
|
|
Well i can now download stuff by sending a user-agent to the http server and other header info. There are still two problems; it takes quite some time for the http server to disconnect when the download is complete and when you decompress a file downloaded, you get an extra file you usually do not get. Can anyone explain why this is happening? Download my test program here that downloads itself to illustrate these problems. It is very rough around the edges(not multi-threaded, ect...) but it should be adequate.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|