Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UrlEncode & UrlDecode

Posted on 2003-10-24
5
Medium Priority
?
4,549 Views
Last Modified: 2012-05-04
I need to encode my data and decode so it can be stored in xml.
Thanks,
Dominik
0
Comment
Question by:Daij-Djan
[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 86

Expert Comment

by:jkr
ID: 9615902
Assuming you are on Windows: To encode, use 'InternetCanonicalizeUrl()', to decode use 'InternetCrackUrl()' with the 'ICU_ESCAPE ' flag.
0
 
LVL 86

Accepted Solution

by:
jkr earned 255 total points
ID: 9615910
0
 
LVL 5

Author Comment

by:Daij-Djan
ID: 9617696
Isnt InternetCrackUrl using URL_COMMPONENTS? Isnt it overkill to also try to split the url.
Especially if it isnt vaild!?
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 120 total points
ID: 9619020
It depends upon your needs (or rather the needs of the host to which you are passing data).  I use this simple fn to pass about 1500 bytes of XML to a host and I have been getting away with it for two years:

//-----------------------------------------------------------------------
// URL encoding of XML formdata
//
void DoUrlEncoding( CString& sXml )
{
      CString sRet, sTmp;
      int nLen= sXml.GetLength();
      for ( int j=0; j< nLen; j++ ) {
            char c= sXml[j];
            if ( isalnum(c) || c=='.' || c=='*' || c=='_' ) {
                  sRet+= c;
            }
            //------I was told must convert, but works in clear text
            else if ( c=='<') sRet += '<';
            else if ( c=='>') sRet += '>';
            else if ( c=='/') sRet += '/';
            else if ( c=='\"') sRet += '\"';
            // else if ( c==' ') sRet += ' ';          // I get away with this
            // else if ( c=='%') sRet += "%%";  // and this
            //----------------------------------
            else if ( c==' ') sRet += '+';      // output + for (space)
            else {
                  sTmp.Format( "%%%2.2X", c);     // output %NN (e.g., %C5 ) for other specials
                  sRet += sTmp;
            }
      }
      sXml= sRet;
}
0
 
LVL 5

Author Comment

by:Daij-Djan
ID: 9619095
The host is an app that stores its data as xml.
I write a plugin for it and i need to encode the data it stores and then, also DECODE it once it is passed back to me.

BTW I am almost sure _I_ have to encode %, too...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

604 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