Thread View: borland.public.cppbuilder.internet.socket
5 messages
5 total messages
Started by Hamid
Sun, 29 Jan 2006 06:09
URLEncode and Unicode
Author: Hamid
Date: Sun, 29 Jan 2006 06:09
Date: Sun, 29 Jan 2006 06:09
4 lines
950 bytes
950 bytes
I'm using TNMURL to encode a url, but seemingly the component fails to encode urls containing Unicode characters. How can I solve the problem? Thanx
Re: URLEncode and Unicode
Author: Remy Lebeau (TeamB)
Date: Mon, 30 Jan 2006 07:06
Date: Mon, 30 Jan 2006 07:06
17 lines
1459 bytes
1459 bytes
"Hamid" <hrz_mir@Yahoo.com> wrote in message news:43dc6a15$1@newsgroups.borland.com... > I'm using TNMURL to encode a url, but seemingly the component > fails to encode urls containing Unicode characters. That is not surprising. Most of the VCL in general, and thus most third-party components, cannot work with Unicode to begin with > How can I solve the problem? Don't use the NetMasters components. Which you should not be using anyway, because it is notoriously buggy and problematic in general. Gambit
Re: URLEncode and Unicode
Author: Mark Jacobs
Date: Tue, 31 Jan 2006 16:15
Date: Tue, 31 Jan 2006 16:15
41 lines
2433 bytes
2433 bytes
Hamid wrote:
> I'm using TNMURL to encode a url, but seemingly the component fails to encode urls containing Unicode characters. How can I solve the problem?
Here are a couple of routines. I'll leave you to work them out, and fire questions at this
post :-
AnsiString mjunescape(AnsiString webstr,bool dopls)
{
int ii,jj=webstr.Length(),kk,mm; AnsiString retv="",pschs="0123456789ABCDEF"; char ch;
for (ii=1;ii<=jj;++ii)
{
ch=webstr[ii]; if (ch=='+' && dopls) { retv+=" "; continue;}
if (ch!='%') { retv+=ch; continue;}
if (ii<jj) if (webstr[ii+1]=='%') { retv+="%"; ++ii; continue;}
if (ii<jj-1)
{
kk=pschs.Pos((char)toupper(webstr[ii+1]));
mm=pschs.Pos((char)toupper(webstr[ii+2]));
if (kk>0 && mm>0) { retv+=(char)((kk-1)*16+mm-1); ii+=2;} else retv+=ch;
}
}
return retv;
}
AnsiString mjescape(AnsiString webstr,bool dospc)
{
int ii,jj=webstr.Length(); AnsiString retv=""; char ch;
AnsiString
pschs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789*@._-$!'()%";
for (ii=1;ii<=jj;++ii)
{
ch=webstr[ii]; if (ch==' ' && dospc) { retv+="+"; continue;}
if (pschs.Pos(ch)>0) retv+=ch; else retv+="%"+IntToHex(ch,2);
}
return retv;
}
--
Mark Jacobs
http://www.dkcomputing.co.uk
Re: URLEncode and Unicode
Author: Peter Evans
Date: Wed, 08 Feb 2006 11:06
Date: Wed, 08 Feb 2006 11:06
34 lines
2023 bytes
2023 bytes
"Hamid" wrote in message news:43dc6a15$1@newsgroups.borland.com...
>
> I'm using TNMURL to encode a url, but seemingly the component fails to
> encode urls containing Unicode characters. How can I solve the problem?
>
> Thanx
>
Hamid,
I made the following work OK, but it uses CppWebBrowser1->Navigate, from
NetMasters, to pull the page in !
//make wide string from the URL that has been read in from
file
//get space, and calc length
wchar_t wcURL[256+1]; int iURL=2*strlen((const
char*)csURL)+1;
//
//change to wide / BSTR
StringToWideChar((String)csURL,wcURL,iURL);
//
//load down the first page of the website
CppWebBrowser1->Navigate(wcURL);
Incidentally, the following seems to work without problem as well:
CppWebBrowser1->Navigate(L"AnyPieceOfGoodHtml.html");
Hope that helps.
Best regards,
Peter Evans.
Re: URLEncode and Unicode
Author: Remy Lebeau (TeamB)
Date: Wed, 08 Feb 2006 18:51
Date: Wed, 08 Feb 2006 18:51
40 lines
2497 bytes
2497 bytes
"Peter Evans" <peter-evans@pelcaro.com> wrote in message
news:43e9cfd9$1@newsgroups.borland.com...
> I made the following work OK, but it uses CppWebBrowser1->Navigate,
> from NetMasters, to pull the page in !
TCppWebBrowser is not a NetMasters component. It is a Borland component
wrapper around the Internet Explorer COM object.
> //make wide string from the URL that has been read in
from file
> //get space, and calc length
> wchar_t wcURL[256+1]; int iURL=2*strlen((const
char*)csURL)+1;
> //
> //change to wide / BSTR
> StringToWideChar((String)csURL,wcURL,iURL);
> //
> //load down the first page of the website
> CppWebBrowser1->Navigate(wcURL);
There is an easier way to do that:
CppWebBrowser1->Navigate(WideString(csURL));
> Incidentally, the following seems to work without problem as well:
>
> CppWebBrowser1->Navigate(L"AnyPieceOfGoodHtml.html");
That is very dangerous. Navigate() expects a BSTR. Using the 'L' keyword
*does not* produce a valid BSTR. All the 'L' keyword does is to tell the
compiler to create a wchar_t* constant instead of a char* constant. A BSTR,
on the other hand, is more than that. It has a 4-byte length value
preceeding the character memory. The 'L' keyword cannot produce that. You
need to use one of the Win32 API's SysAlloc...() functions (which are
wrapped by the WideString class) to produce valid BSTR values.
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads