S-T-R-E-G-A
S-T-R-E-G-A

Reputation: 277

Resolve Proper URL

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).

Upvotes: 0

Views: 194

Answers (3)

Kevin Reid
Kevin Reid

Reputation: 43743

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.

Upvotes: 2

Franci Penov
Franci Penov

Reputation: 75981

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

Upvotes: 0

S.Lott
S.Lott

Reputation: 391818

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

How does that require an API?

Are you asking about the string concatenation API?

Upvotes: 0

Related Questions