?
Solved

CGI ENCODER

Posted on 1999-01-13
5
Medium Priority
?
357 Views
Last Modified: 2013-12-25
Greetings,

I am writing a Unix program which submits some data using the HTTP protocol to a remote CGI script...
I am in need of a C function which will encode a given string (so a CGI program can read it), but I am not sure exactly what should be encoded (i.e. I know all spaces become "+" and fields separated by "&", but don't which characters become hex encoded etc.)
Can anyone provide a C function to Encode a given string?

Thanks.
0
Comment
Question by:idek1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
jconde earned 160 total points
ID: 1830579
The encoding in hexadecimal base.

You must do a for from 0 to strlen(your_string) and if your_string[i] is not numeric, or alphanumeric, you must get the number value of the character, convert it to hex base, and add a % before it.

Example:

this+is+\a\+test

the value for \ is 92, so you need to convert 92 to hex base (5C) and add a % before...

encoded string:

this+is+%5Ca%5C+test

..make any sense??

If you need the code please let me know so I can search my C files!

Regards,

Jorge

0
 

Author Comment

by:idek1
ID: 1830580
Well yes, however, I suspect that the "." (dot) is not encoded and my question is really about what IS and what is NOT encoded using HTTP. Using your algorithm, the "." would be encoded as hex string, because it is neither a character nor a digit, where it really should not be encoded.

idek1
0
 
LVL 7

Expert Comment

by:jconde
ID: 1830581
That depends!!

I have seen browsers that encode everything, and some that don't.

Let me check the algorithms I have (some written by me, some downloaded) and I'll send them to you ok?

--jorge
0
 

Author Comment

by:idek1
ID: 1830582

ok... my email is:
irvingd@bigfoot.com

Thanks for your help,
Idek1
0
 
LVL 8

Expert Comment

by:jhurst
ID: 1830583
As has been said you can encode more than you need.  The ones that need to be encloded are defined in the http protocol specification.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question