views:

1218

answers:

4

Hi,

The last GUI programming I have done was with Visual Basic, which included objects like Winsock and Inet to easily connect to the internet and retrieve the source from webpages.

I just got started into XCode, and was wondering if there is a similar component. I see that there is a Webkit option in the Library, but I have no idea how to use it.

Any help would be appreciated.

A: 

The NSString class have methods to retrieve source from webpages, such as stringWithContentsOfURL:encoding:error:.

For more control, take a look at the classes described in http://developer.apple.com/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html documentation.

WebKit is more like MSIE ActiveX control.

Heng-Cheong Leong
A: 

I want to simulate the browser as well as possible (including cookies, headers, etc). Is the Webkit approach better than the link you just gave me? Sorry I was no more clear in the OP.

Logan Serman
+2  A: 

Webkit is the correct answer. Here's a tutorial from 2003, showing how to build a web browser using webkit:

http://cocoadevcentral.com/articles/000077.php

Basically, webkit lets you embed a web browser in your application UI.

Mike Heinz
+2  A: 

Apple has two guides in the documentation you'll want to look at, URL Loading System and WebKit Objective-C Programming Guide. You'll probably be most interested in the former if you want to request data from a web server behind the scenes, or the latter if you want to actually put a web browser control into your application. Both documents should explain the classes you'll use and the general process, but let me know if you have questions.

A lot of the core Cocoa data types like NSString, NSDate, and even NSArray and NSDictionary have methods for loading data from a URL like Heng-Cheong Leong mentioned, but they abstract away all the low level stuff and probably won't be suitable if you want to deal with HTTP headers.

Marc Charbonneau