# WebBrowserComponent URL\[SOLVED\]

**URL:** <https://forum.juce.com/t/webbrowsercomponent-url-solved/4108>\
**Category:** MacOSX and iOS\
**Created:** [July 20, 2009, 11:57am UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108 "2009-07-20T11:57:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishvesh](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vishvesh](https://forum.juce.com/u/vishvesh)\
**Post date:** [July 20, 2009, 11:57am UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/1 "2009-07-20T11:57:02Z")

</div>

Hi Julian,  
I have been trying couple of things with juce::webbrowsercomponent. If I try to open a url containing braces on mac, the webbrowsercomponent doesn’t display the page  
[  
http://www.google.co.in/search?q={vishvesh}  
 ](http://www.google.co.in/search?q=%7Bvishvesh%7D)

But Safari and other browsers display the page.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 20, 2009, 12:07pm UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/2 "2009-07-20T12:07:49Z")

</div>

Well, it’s just passing the string straight through to the browser component. And I don’t think braces are actually legal in a URL, are they?

Safari is probably being clever and trying to fix any illegal characters before it sends the string, but if I did that, it’d break existing code by double-encoding already encoded URLs.

The URL class has encoding methods that you can use to tidy it up before you send it.

---

<div class="post-metadata">

**Author:** ![vishvesh](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vishvesh](https://forum.juce.com/u/vishvesh)\
**Post date:** [July 20, 2009, 12:25pm UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/3 "2009-07-20T12:25:53Z")

</div>

> [@](#):
>
> And I don’t think braces are actually legal in a URL, are they?

Braces are actually unsafe URL characters but not illegal.  
[  
http://www.faqs.org/rfcs/rfc1738.html  
 ](http://www.faqs.org/rfcs/rfc1738.html)  
I haven’t debugged the webBrowserComponent code yet, But will give it a try soon.

---

<div class="post-metadata">

**Author:** ![vishvesh](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vishvesh](https://forum.juce.com/u/vishvesh)\
**Post date:** [July 20, 2009, 12:34pm UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/4 "2009-07-20T12:34:43Z")

</div>

I encrypted the braces and it worked.  
Just in case someone faces similar problem  
[  
http://www.w3schools.com/TAGS/ref\_urlencode.asp  
 ](http://www.w3schools.com/TAGS/ref_urlencode.asp)

Am guess here, may be safari is checking for unsafe characters and encrypting those before trying to load the page.

---

<div class="post-metadata">

**Author:** ![vishvesh](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vishvesh](https://forum.juce.com/u/vishvesh)\
**Post date:** [July 21, 2009, 3:50am UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/5 "2009-07-21T03:50:38Z")

</div>

Hi Julian,  
I have solved the issue, you would have to add a extra line of code to webBrowserComponent’s “sendWebViewToURL” method.

This is the change i have done

```auto
 void sendWebViewToURL (const char* utf8URL,
                           const char** headerNames, 
                           const char** headerValues, 
                           int numHeaders,
                           const char* postData, 
                           int postDataSize)
    {
		NSString* formattedURL = [NSString stringWithString:[[NSString stringWithUTF8String: utf8URL] stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]]; // added this line, it encodes all non- URL characters
		
		NSMutableURLRequest* r = [NSMutableURLRequest 
								  requestWithURL: [NSURL URLWithString: formattedURL]
								  cachePolicy: NSURLRequestUseProtocolCachePolicy
								  timeoutInterval: 30.0];// pass the formated URL.

        if (postDataSize > 0)
        {
            [r setHTTPMethod: @"POST"];
            [r setHTTPBody: [NSData dataWithBytes: postData length: postDataSize]];
        }

        int i;
        for (i = 0; i < numHeaders; ++i)
        {
            [r setValue: [NSString stringWithUTF8String: headerValues[i]]
                forHTTPHeaderField: [NSString stringWithUTF8String: headerNames[i]]];
        }

        [[webView mainFrame] stopLoading ];
        [[webView mainFrame] loadRequest: r];
    }
```

“stringByAddingPercentEscapesUsingEncoding” encodes all the non-URL/non secure URLcharaters.

I have tested it and it works well. It is safe to put this code in.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 21, 2009, 8:23am UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/6 "2009-07-21T08:23:34Z")

</div>

no, no, no… Like I said above, the goToURL method expects the string to already be encoded. Adding an encoding step there would double-encode it, and break any existing code that uses it!

The idea is that you can use the URL class to build the string that you pass into this function, and that’ll take care of all the messy stuff for you.

---

<div class="post-metadata">

**Author:** ![vishvesh](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vishvesh](https://forum.juce.com/u/vishvesh)\
**Post date:** [July 21, 2009, 8:31am UTC](https://forum.juce.com/t/webbrowsercomponent-url-solved/4108/7 "2009-07-21T08:31:45Z")

</div>

I tried encrypting it twice, using “stringByAddingPercentEscapesUsingEncoding” doesn’t encode the characters already encoded.

But you are right, the URL’s passed to the webbrowser should be valid. I will make changes to my code :). Thanks for the help.
