Solved

CGI ENCODER

Posted on 1999-01-13
5
331 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
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
jconde earned 80 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now