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
Solved

CGI ENCODER

Posted on 1999-01-13
5
339 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 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