Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

URL consists space works on PC browser but not in SDK

obaidjawadobaidjawad Posts: 133Registered Users
Hi guys, I'm sorry for asking too many questions today itself, However I'd like to thank for helping me.
I'm using the URL

http://sme.allomani.com/apps/api.php?action=blog_write&domain_id=1&content=ANY CONTENT&session_id=988259e873667dc7af91f24254b8e354

When I try to pass this Using the UIWebview it doesn't load anything. But when I pass the same URL without any space between "ANYCONTENT" it executes flawlessly.

So, I thought the same that the spaces are not allowed but when I tested on many other browsers of PC's, it works great. Then where I'm going wrong in UIWebview? Please help me.
Tagged:

Replies

  • Duncan CDuncan C Posts: 8,015Tutorial Authors, Registered Users
    Spaces are not allowed in URLs. Period. Browsers "percent escape" them (convert them to %20). You must percent escape user entered strings in URLs.

    Take a look at this link.

    http://www.iphonedevsdk.com/forum/iphone-sdk-development/106300-categories-nsstring-partially-working-p1.html

    The method encodedURLParameterString is what you need.
    Post edited by Duncan C on
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • obaidjawadobaidjawad Posts: 133Registered Users
    First of all I'd like to thank you for replying to my post. And as I was searching for my issue long I thought of why not replace the space in the string, with %20 with the answer you have provided. And I checked doing that and it is working good.

    However would that be a problem lateron? or it is fine and I have to use the link you have provided to me?
  • Duncan CDuncan C Posts: 8,015Tutorial Authors, Registered Users
    Spaces are not legal in URLS, and must be escaped. I don't have a clear understanding of how the URL you are sending is generated. If it is a static URL that never changes, just replace the space with %20 in your code and all is well.

    If you generate a URL from user input, or add any parameters to the URL that might contain spaces or other illegal characters then you will need to write code to percent escape the parameter(s) before adding them to the URL string. Note that you should not escape the whole URL string, since characters like "&" and "/" are needed as part of the URL itself. You only want to escape PARAMETERS that might contain those characters.

    For example, if your url is
    mySite.com/parameter=value&parameter
    and "parameter" is replaced by user input, you should escape that parameter and then put it in your URL string. If you tried to escape the whole URL, you'd get
    mySite.com%xxparameter%xxvalue%xxparameter
    (where the %xx sequences would be replaced with the value of the "/", "=", and "&" characters, which I don't feel like looking up.)

    That would cause the URL to not work.

    If the string "parameter" is supposed to be replaced with "My friends & I"

    Then the URL would look like this:
    mySite.com/parameter=value&My%20friends%20%26%20I
    The "&" character that is part of the syntax of the URL should not be escaped, but the "&" that is part of "My friends & I" should be escaped.
    Post edited by Duncan C on
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • obaidjawadobaidjawad Posts: 133Registered Users
    Nice explaination Thank you so much. My part is


    mySite.com/parameter=value&My%20friends%20%26%20I

    The "&" character that is part of the syntax of the URL should not be escaped, but the "&" that is part of "My friends & I" should be escaped.


    I just replaced the spaces in the URL and it is now working good, and once again really nice explained.
Sign In or Register to comment.