# http\_contentencode not encode space ' ' char

**URL:** <https://forums.digi.com/t/http-contentencode-not-encode-space-char/21305>\
**Category:** Rabbit Software\
**Tags:** http\_contentencode\
**Created:** [April 22, 2020, 10:15am UTC](https://forums.digi.com/t/http-contentencode-not-encode-space-char/21305 "2020-04-22T10:15:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![piaimarco](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@piaimarco](https://forums.digi.com/u/piaimarco)\
**Post date:** [April 22, 2020, 10:15am UTC](https://forums.digi.com/t/http-contentencode-not-encode-space-char/21305/1 "2020-04-22T10:15:36Z")

</div>

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:

```auto

http_contentencode(char __far *dest, /*const*/char__ far *src, int max_dest_len)
{
   const static char encodables[] = "&lt;&gt;@%#" ; /* 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 &gt; 0 &amp;&amp; (*src != '\0') ) {
		/* Encoded things are from 'encodables', or non-ASCII-7 chars. */
		p = strchr( encodables, *src );

		/* Handle '&amp;' specially: */
		if( '&amp;' == *src ) {
			if( max_dest_len &lt;= 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 &lt;= 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 &amp;&amp; (' ' &lt;= *src &amp;&amp; *src &lt; '~') ) {
			*dest++ = *src++;
			max_dest_len--;
		} else
		if( max_dest_len &lt;= 6 ) {
			/* ERROR: Not enough space to hold transfer-coded string. Might need
			 * 5 chars like "@", or 6 chars "" .
			 */
			*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() */

```

---

<div class="post-metadata">

**Author:** ![TomCollins](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/tomcollins/32/37_2.png) [@TomCollins](https://forums.digi.com/u/TomCollins)\
**Post date:** [April 22, 2020, 12:15pm UTC](https://forums.digi.com/t/http-contentencode-not-encode-space-char/21305/2 "2020-04-22T12:15:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![piaimarco](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@piaimarco](https://forums.digi.com/u/piaimarco)\
**Post date:** [April 23, 2020, 8:26am UTC](https://forums.digi.com/t/http-contentencode-not-encode-space-char/21305/3 "2020-04-23T08:26:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![TomCollins](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/tomcollins/32/37_2.png) [@TomCollins](https://forums.digi.com/u/TomCollins)\
**Post date:** [April 23, 2020, 11:11pm UTC](https://forums.digi.com/t/http-contentencode-not-encode-space-char/21305/4 "2020-04-23T23:11:14Z")

</div>

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”.)
