Are you sure it's not the trailing forward slash on your root?

FYI, the way that certain characters are encoded after a ? is different than 
how you would normally do it. Just in case you need to escape spaces within 
parameters, use a + after the ?.

In any case, what we ended up doing was to build the NSString and make sure it 
was properly formatted first.  This way, we could easily copy and paste it into 
a browser session and verify that the string will make a valid URL.

Once we had that, we simply did an NSURL URLWithString and we would always know 
it would be a good URL and one that is easily testable if something goes wrong.

I think we made sure the root was properly encoded first, then ran the query 
string through an encode method that was fit for parameters after the ?, 
appended those results into one string and did the URLWithString.

Hope this helps.

Cheers.
- Alex

On Aug 29, 2013, at 2:02 PM, Koen van der Drift wrote:

> I'm having some difficulties constructing a URL from a baseURL and a 
> relativeURL when the relativeURL starts with a question mark:
> 
>    NSURL *baseURL = [NSURL URLWithString: @"http://www.test.com/test/";];
>    NSString *relativeString = @"?query=test";
> 
>    NSURL *url = [NSURL URLWithString: relativeString relativeToURL: baseURL];
> 
> This results in the following url:
> 
> ?query=test -- http://www.test.com/test/
> 
> While I want it to be:
> 
> http://www.test.com/test/?query=test
> 
> 
> I can just generate the whole URL at once, but I was wondering why I get this 
> behavior?
> 
> 
> Thanks,
> 
> - Koen.
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to [email protected]


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to