The MASM Forum

General => The Laboratory => Topic started by: guga on April 27, 2019, 09:32:07 AM

Title: URL Encoder/decode/escape/unescape
Post by: guga on April 27, 2019, 09:32:07 AM
Hi guys

Someone have a example of how to use the necessary apis to do a URI Encode/encode ? (And also, uri escape/unescape) ?

The goal is to do things like this:
Input text:
"Hello World.
From 2019."

Output text:


Hello world. My name is Guga.How are you doing ?

And using also the escape/unescape routines as in: This have some info too of escape/unescape method)

Note: What is needed is to convert/encode/escape a large text file (Around 45 Mb of plain text. In and out utf8 format) and do the operation back.

I´m doing a translation routines using google api, but i faced this tiny problem of encoding (or escape -  i don´t know exactly wich one of them is the proper way to fix. So´, i´ll test it both.). It seems google handles better using escape texts rather then encoded.
Title: Re: URL Encoder/decode/escape/unescape
Post by: AW on April 27, 2019, 04:03:39 PM
You don't need, I mean you should not URL-encoded, large amounts of data.
This is for GET, where data is sent on the command line after the url.

Large amounts of data are sent using POST. With POST, you define what type of data you are sending on the Content-Type of the header. You fill in the remaining header fields, after that you insert a couple of carriage returns/line feeds and then append the data you want to send.

This is the way servers send HTML web pages to your browser, as you know they are not URL-encoded. Or when you receive .zipped files.
Title: Re: URL Encoder/decode/escape/unescape
Post by: morgot on April 27, 2019, 07:39:29 PM
There is sample in pure Masm, but comments in Russian

desciption (rus)
Title: Re: URL Encoder/decode/escape/unescape
Post by: AW on April 28, 2019, 02:08:20 AM
There is sample in pure Masm, but comments in Russian

desciption (rus)

At first sight it appears to work, except that transliteration part, (the last option of the combo box). Of course, it may work with the Windows-1251 encoding (Cyrillic). 
Title: Re: URL Encoder/decode/escape/unescape
Post by: TimoVJL on April 28, 2019, 03:42:53 AM
One idea to convert to an asm code.
Code: [Select]
//! # $ & ' ( ) * + , / : ; = ? @ [ ]
//%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
// "!*'();:@&=+$,/?%#[]";
char url_table[256] =
{// 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x 1x
1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1, // 2x 3x
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0, // 4x 5x
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1, // 6x 7x
short hex_table[256] =

//char *IntToHex(int nNum, char *szBuf, int nLen);
void url_escape(char *s, char *so)
while (*s) {
if (url_table[*s])  {
*so++ = '%';
//IntToHex(*s, so, 2);
*(short*)so = hex_table[*s];
so += 2;
} else *so++ = *s;
*so = 0;

int __cdecl main(void)
char s1[] = "Hello World.\nFrom 2019.\nHello world. My name is Guga.How are you doing ?\n";
char s2[512];
url_escape(s1, s2);
printf("%s\n", s2);
return 0;
Code: [Select]
Hello%20World.%0AFrom%202019.%0AHello%20world.%20My%20name%20is%20Guga.How%20are%20you%20doing%20%3F%0Aobjconv result in zip
Title: Re: URL Encoder/decode/escape/unescape
Post by: guga on April 28, 2019, 09:40:15 AM
Thank you a lot, guys.

This will really be helpfull. I´m doing a translator from english to portuguese using google translator, that uses those encodings as the result. I´ll open another thread on this subject because the server is returning an error 503  after downloading some amount of data.