Solved

UrlEncode & UrlDecode

Posted on 2003-10-24
5
4,544 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 85 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 40 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Create string splitting user defined function in C++ 23 351
FMX enumerated colours 2 152
Autosar OS Multicore Share Resources confusion ? 2 189
C++ Code Issue 4 47
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

739 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