white space in urls

white space in urls

This question is answered

Hi,

we have a requirement where we get the URL of a blog post  using telling blogpost API and make it as a hyperlink. In my case the URL contains a space character. therefore the hyperlink is not getting formed correctly.

Example - the URL is http://localhost/telligent evolution/........./blogpost.aspx

but the hyperlink anchor tag when assigned the above value, contains only

http://localhost/telligent

is there any way to encode URL so that white space becomes %20 ?

Thank you.

Verified Answer
  • Thanks Dan.

    This was my code:

    -----------------------------

    #set($pagedListResponse = $core_v2_blog.List("%{UserId = $core_v2_user.Accessing.Id}"))

    #foreach ($blog in $pagedListResponse)

       <a href="$blog.Url">$blog.Name -- $blog.Url</a><br />

    #end

    ------------------------------

    --> I had missed the double quotes around the $blog.Url for the href. The problem was solved when i placed double quotes around it.

    :)

All Replies
  • URLs returned from the APIs should already be URL encoded, which should replace spaces with %20. It looks like the name of your web application under localhost is "telligent evolution" with a space. We may not be url encoding the host/application part of the URL. One solution would be to rename the application to remove the space. Another option might be to manually encode the application part of the URL in the control panel: Control Panel > Site Administration > Setup > General Site Settings. I assume the value in the Default Site Url field is http://localhost/telligent evolution - you can try setting that to http://localhost/telligent%20evolution. Note that you will need to update that if you change your application name in IIS to remove the space. And finally you could just manually encode any spaces as %20 when getting the URLs via the API, but I would opt for one of my other suggestions first to allow the framework to do the work rather than apply a workaround.

  • Thanks Dan. Will try that and let you know. :)

  • Thanks Dan.

    This was my code:

    -----------------------------

    #set($pagedListResponse = $core_v2_blog.List("%{UserId = $core_v2_user.Accessing.Id}"))

    #foreach ($blog in $pagedListResponse)

       <a href="$blog.Url">$blog.Name -- $blog.Url</a><br />

    #end

    ------------------------------

    --> I had missed the double quotes around the $blog.Url for the href. The problem was solved when i placed double quotes around it.

    :)