Home/Support/Support Forum/http_contentencode not encode space ' ' char
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

http_contentencode not encode space ' ' char

0 votes
I have encontered a problem encoding a space ' ' char in the function http_contentencode.
I would like to share the solution that i have implemented
in the http.lib i have modified the function as belove:
Code:
http_contentencode(char __far *dest, /*const*/char __far *src, int max_dest_len) { const static char encodables[] = "<>@%#" ; /* Array of chars we must change */ auto char __far * orig_dest_ptr; auto char __far * p; auto int more; orig_dest_ptr = dest; --max_dest_len; /* Ensure space for terminating NUL char */ while( max_dest_len > 0 && (*src != '\0') ) { /* Encoded things are from 'encodables', or non-ASCII-7 chars. */ p = strchr( encodables, *src ); /* Handle '&' specially: */ if( '&' == *src ) { if( max_dest_len <= 5 ) { /* ERROR: Not enough space to hold transfer-coded string. */ *dest = '\0'; return NULL; } else { _f_strcpy( dest, "&amp;" ); src += 1; dest += 5; max_dest_len -= 5; } }else if( ' ' == *src ) { if( max_dest_len <= 3 ) { /* ERROR: Not enough space to hold transfer-coded string. */ *dest = '\0'; return NULL; } else { _f_strcpy( dest, "%20" ); src += 1; dest += 3; max_dest_len -= 3; } } else if( NULL == p && (' ' <= *src && *src < '~') ) { *dest++ = *src++; max_dest_len--; } else if( max_dest_len <= 6 ) { /* ERROR: Not enough space to hold transfer-coded string. Might need * 5 chars like "&#64;", or 6 chars "&#127;" . */ *dest = '\0'; return NULL; } else { /* There is room to perform at least one more transfer-coding. */ more = sprintf(dest, "&#%d;", (unsigned char) *src++); dest += more; max_dest_len -= more; } } *dest = '\0'; return( orig_dest_ptr ); } /* end http_contentencode() */
asked Apr 22 in Rabbit Software by piaimarco New to the Community (3 points)
edited Apr 22 by TomCollins

Please log in or register to answer this question.

1 Answer

0 votes
 
Best answer
There's no need to change spaces in HTML -- I think you're looking at the wrong function.

If you need to convert space to %20, you should be using url_encodestr() from url.lib. It was designed for formatting x-www-form-urlencoded data to pass as the query string in an HTTP GET URL, or the body of an HTTP POST.
answered Apr 22 by TomCollins Veteran of the Digi Community (1,870 points)
selected May 12 by TomCollins
Yeah
i have modify the http_contentencode because I haven't find the url_encode function in the user manual TCP/IP vol2 (and in any other manual....)

Many thanks.
Marco Piai

I'm so happy, i have made a very functional board with RCM6760 that can control fan and temperature, send data to server iot and controlled wia web. upgrade fw from iot server and also web. Great!
It's in Lib/Rabbit4000/tcpip/url.lib.

The manuals are outdated, so I recommend the built-in function help.  If you see a function that you want documentation on, try putting your cursor in the name (in an editor window of the Dynamic C IDE) and then pressing CTRL-H.  Many functions have built-in function help.

You can also use "Find in Files" (CTRL-SHIFT-F) to search all Libraries and Samples for a particular name or even a regular expression (grep pattern).  That can help to locate undocumented functions, or find examples of how a particular function was used from other libraries and the samples.

(Also note that when "url encoding" you can convert spaces to "+" instead of "%20".)
...