- Tonton Luc
- VIP Member
- Posts: 204
- Joined: 16 Oct 2001 23:01
vPcURL encoded an URL
Hi,
Is there any vPcURL curl_easy_setopt
Is there any vPcURL curl_easy_setopt
- Jan de Lint
- VIP Member
- Posts: 83
- Joined: 6 Mar 2000 0:01
Re: vPcURL encoded an URL
Yes, there is curl_easy_escape (and curl_easy_unescape) in VPcURL.iTonton Luc wrote:Hi,
Is there any vPcURL curl_easy_setopt
]an
- Tonton Luc
- VIP Member
- Posts: 204
- Joined: 16 Oct 2001 23:01
Hi Jan,
curl_easy_escape convert ALL special caracters like "-","_","/",".",etc... too, but it's not my goal.
Before to call :I need to convert only some special caracters like in this URL :
curl_easy_escape convert ALL special caracters like "-","_","/",".",etc... too, but it's not my goal.
Before to call :
Code: Select all
C:curl_easy_setopt(vPcURLconst::cURLOPT_URL, vPcURL::s(URL)),
https://www.bmw.fr/dam/brandBM/marketFR ... fs_BMW_S[b][/b]rie_4_Coupe_Cabriolet_Juillet_2015.pdf
-
- VIP Member
- Posts: 452
- Joined: 5 Nov 2000 0:01
I have acquired an irrational (or not) abhorrence of string generation, thanks to VIP 5.2! For simple tasks like converting a URL there's not much risk of stack overflow, but I still like to use routines like this:
Code: Select all
class predicates
url_encoded : ( string ) -> string EncodedURL. % Move to .CL file
encode_urlChars : ( char_list, char_list ) -> string.
clauses
url_encoded( URL ) = EncodedURL :-
URL_Chars = string::toCharList(URL),
EncodedURL = encode_urlChars( URL_Chars, [] ).
encode_urlChars( [], TempCC ) = string::createFromCharList(TempCC).
encode_urlChars( [H|T], TempCC ) = U :-
char_urlCode(H,CC),
!,
NewTemp = list::append(TempCC,CC),
U = encode_urlChars(T,NewTemp).
encode_urlChars( [H|T], TempCC ) = U :-
NewTemp = list::append(TempCC,[H]),
U = encode_urlChars( T, NewTemp ).
class facts
char_urlCode : ( char, char_list ).
clauses
char_urlCode(' ', ['%','2','0']).
char_urlCode('!', ['%','2','1']).
char_urlCode('"', ['%','2','2']).
char_urlCode('#', ['%','2','3']).
char_urlCode('$', ['%','2','4']).
char_urlCode('%', ['%','2','5']).
char_urlCode('&', ['%','2','6']).
char_urlCode('\\', ['%','2','7']).
char_urlCode('(', ['%','2','8']).
char_urlCode(')', ['%','2','9']).
char_urlCode('*', ['%','2','A']).
char_urlCode('+', ['%','2','B']).
char_urlCode(',', ['%','2','C']).
char_urlCode('-', ['%','2','D']).
char_urlCode('.', ['%','2','E']).
char_urlCode('/', ['%','2','F']).
-
- VIP Member
- Posts: 106
- Joined: 6 Mar 2000 0:01
-
- VIP Member
- Posts: 452
- Joined: 5 Nov 2000 0:01
Re:
I've done it that way too, but I worry about an unnoticed typing entry in entering the lists. Fact structures are easier for me to visually check in code, but I do know that database operations can be slower than list operations.
- Thomas Linder Puls
- VIP Member
- Posts: 1424
- Joined: 28 Feb 2000 0:01
Given this description https://en.wikipedia.org/wiki/Percent-encoding, I would do something like this:
This code also encodes the Reserved Characters, so to create a URL you will have to encode the parts and then construct the URL from them. E.g.:
I assume the Server does not need to be urlEncoded.
Code: Select all
class predicates
urlEncode : (string String) -> string Encoded.
clauses
urlEncode(String) = outputStream_string::getString({ (S) :- urlEncode2(S, string8::toUtf8(String)) }).
class predicates
urlEncode2 : (outputStream S, string8 Utf8).
clauses
urlEncode2(S, Utf8_1) :-
Char8 = memory::getChar8(Utf8_1, Utf8_2),
if 0 <> Char8 then
urlEncodeChar8(S, Char8),
urlEncode2(S, Utf8_2)
end if.
class predicates
urlEncodeChar8 : (outputStream S, char8 Char8).
clauses
urlEncodeChar8(S, Char8) :-
Char = string8::mapToChar(Char8, utf8),
if 'A' <= Char and Char <= 'Z'
or 'a' <= Char and Char <= 'z'
or '0' <= Char and Char <= '9'
or '-' = Char
or '_' = Char
or '.' = Char
or '~' = Char
then
S:write(Char)
else
S:writef("%%%02x", Char8)
end if.
Code: Select all
URL = string::format("http://%/subdir/query?name=%&value=%", Server, urlEncode(Name), urlEncode(Value))
Regards Thomas Linder Puls
PDC
PDC
- Jan de Lint
- VIP Member
- Posts: 83
- Joined: 6 Mar 2000 0:01