views:

50

answers:

3

How can I turn domain.com into https://www.domain.com (the actual address)? Is there an easy API for this?

The purpose is to allow a user to enter a domain in preferences and allow my app to convert that into a fully qualified web URL like a web browser does when I type google.com it returns http://www.google.com (ish).

A: 

What's so hard about putting "http://www." in front?

How does that require an API?

Are you asking about the string concatenation API?

S.Lott
A: 

Use the NSURL class. More specifically, use initWithScheme:host:path where scheme is "http", host is your string and path is empty.

Franci Penov
A: 

If typing your domain.com results in https://www.your domain.com then the server is redirecting. Here is a rule to follow:

  • Construct "https://domain the user typed". Connect to that, and follow any 301 (permanent) redirects until you get a 200 response. Save the URL you end up at as the permanent one.
  • If your connection failed, try again with http:// instead of https://.

Do not assume that the "proper" URL contains "www."; if it should, then the server will redirect.

Kevin Reid