Regarding URL Encoding in C#

hello,
We have a need to compress a string into a representation that is shorter than the original string then to decompress it.  I wanted to know if there is a way to do this in .NET for strings that are about 1000-1500 characters (not extremely long, but
we need to compress them for use in a URL/querystring)(maximum length limit allowed is 256).
plz help me i am a beginner in programming.....plzzzzzzzzzzzzzz
<aside class="meta trailing-meta" style="font-family:inherit;padding:10px 0px;min-height:55px;border-top-width:1px;border-top-style:dotted;border-top-color:#d5d5d5;">
</aside>
Latheesh K Contact No:+91-9747369936

I don't know what Magnus is on about with server urlencode.
That's.... not going to do you any good at all.
You could potentially zip a string and send that:
public static void CopyTo(Stream src, Stream dest) {
byte[] bytes = new byte[4096];
int cnt;
while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0) {
dest.Write(bytes, 0, cnt);
public static byte[] Zip(string str) {
var bytes = Encoding.UTF8.GetBytes(str);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream()) {
using (var gs = new GZipStream(mso, CompressionMode.Compress)) {
//msi.CopyTo(gs);
CopyTo(msi, gs);
return mso.ToArray();
public static string Unzip(byte[] bytes) {
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream()) {
using (var gs = new GZipStream(msi, CompressionMode.Decompress)) {
//gs.CopyTo(mso);
CopyTo(gs, mso);
return Encoding.UTF8.GetString(mso.ToArray());
static void Main(string[] args) {
byte[] r1 = Zip("StringStringStringStringStringStringStringStringStringStringStringStringStringString");
string r2 = Unzip(r1);
from
http://stackoverflow.com/questions/7343465/compression-decompression-string-with-c-sharp
However
You might want to first consider using  a cookie instead if that is an option.
Note that either way you will need some actual code running on the client in order to do this.
Unless something very strange is going on then this would seem to not actually be an asp.net question.
Since it's calling something on a web server as opposed to the thing that is called on that web server I would think this forum could well be the correct one.
If this is to happen on a client from a web page then you will need javascript rather than c#.
http://stackoverflow.com/questions/4570333/string-compression-in-javascript
Please don't forget to upvote posts which you like and mark those which answer your question.
My latest Technet article - Dynamic XAML

Similar Messages

  • Query regarding URL Encoding......in struts

    Hi Friends,
    I am working in Struts.
    Now in some cases i have to send some data (like some id or falg value ) in URL as queryURL.
    now when the page calls at that time on the address bar i saw the whole URL.
    I wanted to encode that URL.so that no one can undestand the actual parameter values and name.
    So can any one help me about this.
    Thank You,
    Ajay Patel

    You could simply POST the data as opposed to using GET. Though it doesn't encode/ encrypt the data, but simply adds the parameters into the body of the request. If someone were to look at your requests, they'd be able to see this data.
    As for actually hiding it through encryption, you could get JavaScript libraries to do this on form submit but I doubt you'd need that much security. You could also try base64 encoding for a simpler approach.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • BSP Url encoding

    Hi all!
    I'd like to use URL encoding (I guess base64) to mask url parameters in our URL (instead of default.htm?param1=value&param2=value etc.) to prevent URL manipulation. In most parts of our application we use PopUp-Windows without the location bar of the browser, but we have email links to workitems which launch BSPs and these new opened browser windows do have a location bar and a URL which can be manipulated.
    How do you set up URL encoding in your BSP application? (entries in the BSP service of /sicf for example or BSP Application Attributes ?). Is there a way to encode the only parts of the application? How to use and when the if_http_utility->en/decode_base64 methods?
    best regards,
    Christoph

    did you try the following?
    ex. you have page a.htm and from there you are calling page b.htm with params param1 and param2.
    use
    CALL METHOD cl_http_utility=>if_http_utility~encode_base64
                     EXPORTING
                       unencoded =  param1value
                     receiving
                       encoded   = param1value .
    and pass this as the value for param1 and call the URL for page b.htm.
    and within page b.htm decode it and use .
    CALL METHOD cl_http_utility=>IF_HTTP_UTILITY~DECODE_BASE64                 EXPORTING
                       encoded =  param1value
                     receiving
                       decoded   = param1value .
    <b>Sample application:</b>
    Create a BSP application withe two pages a.htm and b.htm
    and have a page attribute called name in both the pages.
    <u><b>a.htm layout code</b></u>
    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <htmlb:content design="design2003">
      <htmlb:page title = " ">
        <htmlb:form>
    <%
    if name is initial .
    name = sy-uname .
    endif .
    %>
          <htmlb:textView     text          = "<%= name %>"
                              design        = "EMPHASIZED" />
    <%
    CALL METHOD cl_http_utility=>if_http_utility~encode_base64
                     EXPORTING
                       unencoded =  name
                     receiving
                       encoded   = name .
    %>
          <htmlb:button       text          = "Press Me"
                              onClientClick       = "javascript:window.open('b.htm?name=<%= name %>');" />
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    <u><b>b.htm layout code</b></u>
    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <htmlb:content design="design2003">
      <htmlb:page title = " ">
        <htmlb:form>
    <%
    CALL METHOD cl_http_utility=>if_http_utility~DECODE_BASE64
                     EXPORTING
                       encoded =  name
                     receiving
                       decoded   = name .
    %>
          <htmlb:textView     text          = "<%= name %>"
                              design        = "EMPHASIZED" />
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    Hope this helps.
    Regards
    Raja

  • Newbie ERROR- URL Encoded SQL Length exceeds allowed 32K limit

    My SQL Query worked fine yesterday.( I'm still in developing mode)
    I made a copy of it and put it into a text file.( Just to be sure I had it.)
    Today When I tried to run it in APEX , I get error
    URL Encoded SQL Length exceeds 32K limit.
    Is there any way to tell how the size of my query ( for example 33K)
    is using?
    TIA
    Steve42

    I had to put out some other fires for the last few days.
    I'm trying to use it in SQL worksheet.
    That is my entire error message. It does NOT have an Error #.
    Product Build: 3.0.0.00.20
    TIA,
    Steve42

  • Hi, how to use URL encoding in jsp

    hi, how to apply URL encoding in jsp for a string, could u pls suggest some ideas to use URL encoding in jsp
    thank you in advance

    hi, thnx for the reply, but my problem is to use url encoding method
    i would u like to know how to represent in jsp program i have asp code some thing like this
    href='/project/tel_number.asp?team=<%=DbRecTeam("id")%>&name=<%=Server.URLEncode(DbRec("name"))%>'
    i would like to know how replace that Server.URLEncode stmt in jsp, could u pls suggest some equivalent method for the above stmt
    thanx in advance

  • XML to URL Encoded (XSLT?)

    I have some data in a Document object and need to convert it to URL encoded format so, for example this:
    <share>
    <code>GSK</code>
    <price>13.34</price>
    </share>
    becomes something like...
    &code=GSK&price=13.34& ...
    I've been looking into doing this with XSLT but have run into difficulties. Do you think this is the best way of solving this problem, or is there another easier way?
    Thanks.

    I did something similar, basically takes a incoming XML file and output a HTML with certain link containing XML element value as query string. One of the things you have to be careful is, like Dr. Clap mentioned, to properly encode the value. I accompolished by using java extension in my XSL.
    For example:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:encode="java.net.URLEncoder"
              extension-element-prefixes="encode"
              version="1.0">
         <xsl:template match="/">
              <xsl:variable name="myURL" select="concat('?blah=', encode:encode($myValueFromXML))" >
         </xls:template>
    </xsl:stylesheet>

  • URL Encoding and UTF8

    Hello Friends,
    I have been working on this problem for some time now. I have a web page that has forms fields like first name, last name etc. and then posts the data back to a servlet that writes it into a file that is utf-8 encoded. The web page has charset specified as utf-8. I was assuming that data would be sent back in the url as utf-8. I entered some japanese data copied from a japanese web page. When I looked at the file into which the form data was written I saw that it wasn't even close to utf-8 or unicode encoding of the data I had posted. For eg. I entered a japanese character: '\u4F1A' which is utf-8 encoded as 'E4 BC 9A'. But the data written into the file is '25 45 34 25 42 43 25 39 41'. This is of course because the data is url encoded which is '%E4%BC%9A', since 45 is hex for E, 34 is hex for 4 and so on. Now the question is how is it that I proceed to get the right utf data back. I am using a jrun server. Is there something that I need to set here in order to get the right characters back.

    The UTF-8 encoded sequence of bytes of the character '\u4F1A' is {-E4, -BC, -9A}, and the character '-' is (char)0x2d instead of (char)0x25. And I suppose 25 should be 2d.

  • URL Encoder not working in Netscape

    Hi All,
    I am using url encoding in my servlet for redirecting a request. The query string values has some spaces in them. The code I have used is shown below
    String mname = "Jason Perry"
    response.sendRedirect
    ("http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp="+price.toString()+"&mname="+URLEncoder.encode(mname)+"&mtxnid=UY675432");
    Please note that 194.216.8.238:8081 is an IP of another server located outside our network.
    In Netscape the url is shown as http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432
    The space is not getting replaced with the plus.
    But I have observed that if the redirection is to the same server on which the servlet is running, it works fine.
    I am at loss as to why url encode is not working when routing the request to another server. I am using Netscape 4.77 .
    This is works in IE fine.
    Your inputs are appreciated.
    Thanks
    Malini

    Yeah had this problem before, use the java.net.URLEncoder class:
    <%@ page language="java" import="java.net.URLEncoder"%>
    <%
    String url = "http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432"
    String encodedUrl = URLEncoder.encode(url);
    response.sendRedirect(encodedUrl);
    %>

  • Apache plugin url encoding

    the following is on HP Apache-based Web Server/1.3.26
    with the mod_wl.so from 6.1 sp3 proxying to a 6.1 sp3 backend and I tried setting
    up QueryFromRequest ON to no avail.
    I am having the following problem with the BEA proxy plugin for Apache. I have
    a very simply scenario to demonstrate it. Lets say that you have the following
    directory/file structure:
    /applications
         /DefaultWebApp
              spaceLink.htm
              /space demo
                   resource.htm     
    NOTE: There is a "space" in the "space demo" directory name.
    Now, spaceLink.htm has a link to the file resource.htm in the "space demo" directory.
    Here is the html:
    <html> <body> click here </body> </html>
    Now assume that apache is sitting in front of this BEA box and proxying requests
    to the BEA box.
    If the Apache-BEA proxy plugin is proxying the request to BEA, then the request
    is made correctly from the browser to the proxy as:
    GET /space%20demo/resource.htm HTTP/1.1
    Notic the browser is correctly URL encoding the request.
    BUT, the apache-BEA proxy plugin is incorrectly proxying the request to the BEA
    box:
    GET /space demo/resource.htm
    Notice the Apache-BEA proxy is not URL encoding the request, so when BEA gets
    it he thinks this is a request for "/space" and "demo/resource.htm" is the http
    version.
    This problem DOES NOT happen if I use the generic http proxy module provided with
    Apache.
    Has anyone seen this problem before?
    Please get back to me if you have some information.
    Thanks,
    Cole Crawford
    Paymentech

    the following is on HP Apache-based Web Server/1.3.26
    with the mod_wl.so from 6.1 sp3 proxying to a 6.1 sp3 backend and I tried setting
    up QueryFromRequest ON to no avail.
    I am having the following problem with the BEA proxy plugin for Apache. I have
    a very simply scenario to demonstrate it. Lets say that you have the following
    directory/file structure:
    /applications
         /DefaultWebApp
              spaceLink.htm
              /space demo
                   resource.htm     
    NOTE: There is a "space" in the "space demo" directory name.
    Now, spaceLink.htm has a link to the file resource.htm in the "space demo" directory.
    Here is the html:
    <html> <body> click here </body> </html>
    Now assume that apache is sitting in front of this BEA box and proxying requests
    to the BEA box.
    If the Apache-BEA proxy plugin is proxying the request to BEA, then the request
    is made correctly from the browser to the proxy as:
    GET /space%20demo/resource.htm HTTP/1.1
    Notic the browser is correctly URL encoding the request.
    BUT, the apache-BEA proxy plugin is incorrectly proxying the request to the BEA
    box:
    GET /space demo/resource.htm
    Notice the Apache-BEA proxy is not URL encoding the request, so when BEA gets
    it he thinks this is a request for "/space" and "demo/resource.htm" is the http
    version.
    This problem DOES NOT happen if I use the generic http proxy module provided with
    Apache.
    Has anyone seen this problem before?
    Please get back to me if you have some information.
    Thanks,
    Cole Crawford
    Paymentech

  • Problem in URL Encoding  in J2ME

    Hi,
    I have a problem in URL Encoding in J2ME. As i read thru the J2ME APIs, i found that J2ME doesn't support it.
    Or can i use the URL Encoding in J2SE to modify and put into J2ME?
    Or someone out there have done such coding?
    Reply me!
    Thanks!...

    like this:
    public static String URLEncoder(String str) {
    if (str == null) return null;
    StringBuffer resultStr = new StringBuffer( str.length() );
    char tmpChar;
    for( int ix=0; ix<str.length(); ix++ ) {
    tmpChar = str.charAt( ix );
    switch( tmpChar ) {
    case ' ' : resultStr.append( "%20" );
    break;
    case '-' : resultStr.append( "%2D" );
    break;
    case '/' : resultStr.append( "%2F" );
    break;
    case ':' : resultStr.append( "%3A" );
    break;
    case '=' : resultStr.append( "%3D" );
    // System.out.println( "tmpChar = '=' " + "add %3D " );
    break;
    case '?' : resultStr.append( "%3F" );
    // System.out.println( "tmpChar = '?' " + "add %3F " );
    break;
    case '#' : resultStr.append( "%23" );
    break;
    case '\r' : resultStr.append( "%0D" );
    break;
    case '\n' : resultStr.append( "%0A" );
    break;
    default : resultStr.append( tmpChar );
    break;
    return resultStr.toString();
    }

  • I have a string in URL encoded format. How do I unencode?

    I'm sure there is a single command for this but I can't find it, so my workaround is a long list of 'replace' commands :-(
                    vari = vari.replace(/%22/g,"'");
                    vari = vari.replace(/%20/g," ");
                    vari = vari.replace(/%3C/g,"<");
    etc.
    Help!!! How do I unencode  my URL encoded string?

    http://livedocs.adobe.com/flex/3/langref/package.html#unescape()
    try this link..
    unescape(); function.. it is a global function
    hope this helps,
    BaBo,

  • Sending document to oracle xml gateway web service and body is url encoded

    Hello,
    a question from a complete newbie to web services. I have some code that is sending a soap message to an oracle xml gateway web service. In the soap message the values in the soap body look like &lt ;CNTROLAREA&gt ;
    when I would be expecting <CNTROLAREA>. What I have been told is that the content of the ReceiveDocument element has been url encoded which causes the &lt and to correct it I need to change the paramater type from object to xmlnode and to build the request as an xmldocument. The xmlnode and xmldocument comes from a .net guy so I've been trying to find the equivalent in java but am not having any luck. I have a lot of reading to do but was wondering if someone might be able to point me in the right direction on how to correct the problem. I captured the soap message being sent using tcpmon. Why does the body have the &lt instead of the < as I was expecting and is there an xmldocument type? The header part of the soap message looks as I expect. "><soapenv:Header><ns1:XMLGateway_Header xmlns:ns1="http://xmlns.oracle.com/apps/fnd/XMLGateway"><ns1:MESSAGE_TYPE>XML</ns1:MESSAGE_TYPE>. It is being sent as a com.oracle.xmlns.apps.fnd.XMLGateway.XMLGateway_Header type.
    thanks
    Thanks
    Edited by: twf123 on May 5, 2010 11:59 AM
    Edited by: twf123 on May 5, 2010 12:00 PM

    twf123 wrote:
    What I have been told is that the content of the ReceiveDocument element has been url encoded which causes the &lt and to correct it I need to change the paramater type from object to xmlnode and to build the request as an xmldocument. Where do you change the parameter type?
    The xmlnode and xmldocument comes from a .net guy so I've been trying to find the equivalent in java but am not having any luck. How do you get the data from .net guy? Which interface do you use? What processing do you do after receiving the data?

  • URL encoding special characters in episode name

    Hello,
    Configuration :
    1 capture agent on a MAC MINI under MAC OS X 10.6.5
    1 PCP2 server on an XServe under MAC OS X 10.6.5
    I encounter this problem since 10.6.5 update :
    When I stop a Podcast capture, if episode name is for example abcd#, '#' character is "URL encoded" to '%23' sequence. So the final file name of the podcast is abcd%23.m4v instead of abcd#.m4v.
    This was not the case under 10.6.4.
    I tried this solution : renaming the file adding a task in the workflow ; this task launches a bash script which renames all files replacing '%23' sequences by a '#' character.
    Files are well renamed, but the task don't give hand back, and XGrid task never ends.
    Got this error in /var/log/system.log :
    sandbox [nnn] : bash(12146) : deny file-ioctl /path/to/bash-script
    Thanks for help

    Problem solved !
    I had a problem with rights on my podcasts directory.
    So, for those who are interested, you can add a task to your workflow, for example a bash batch file which renames all files in your podcast directory whose name contains a special character :
    for fic in `ls`
    do
    mv $fic `echo $fic | sed -e s/%23/#/g`
    done
    the additional workflow task must contain 2 items :
    --- an item "command" of type String with the path of your batch file as value
    --- an item "dependsOnTasks" of type array with an element of type string with "postflight" as value

  • XSL and url encoded data issue

    I have a large XML document, which has the data in it URLEncoded to escape the nasty chars.
    When I run it through the xalan XSL parser and feed the output to the browser in my servlet, the resultant html has the URLEncoded chars in it. For instance the '/' is still showing up at %2F etc... However, if I can't URLDecode the whole xml document. Is there a simple way for decode the URL chars, without doing too much trickery?
    Thanks!
    Modoc

    You can URL-encode XML data if you like, whatever you mean by "nasty chars" I don't know. The result is perfectly legitimate XML and XSLT will translate it perfectly well. But it won't decode it, that is none of its business. I suppose it would be possible to write an XSLT function to do URL-decoding, but my preference would be to do that some other way. Or not to URL-encode in the first place.

  • URL encoding in web.show_document

    Hi.
    I have to pass some parameteres with spaces and such in them. Is there any available pl/sql functions to url encode/decode ?

    Thanks.
    I had some trouble though, as the compiler didn't recognize it. It turned out that this package did not exist in the v8 db we're using for development, but the recent 9i production db had it.
    We decided to put the parameter in question into the db, and extract it from the report instead of passing it on the url...

Maybe you are looking for

  • Can't delete files from external hard drive

    So here's an interesting problem that I've never run across. I have a Western Digital hard drive plugged in and I was deleting some files off it today when suddenly it started saying that there were some files in use and it couldn't delete those. I h

  • How do I use time machine to backup to an external hard drive plugged into my airport extreme

    How do I use time machine to backup to an external hard drive plugged into my airport extreme?  I used to be able to but now time machine will not recognize my hard drive to select as a backup when plugged into my airport extreme.  I'm not sure what

  • Can i connect to the database through the internet

    hi all i installed a database oracle 8i enterprise edition on a pc that exists in a town far from me . i wonder can i connect to this database through the internet from my house please i need a answer thanks in advance

  • Updating a large table

    Hello, We need to update 2 columns on a very large table (20000000 records). Every row in the table is to be updated and the client wants to be able to update the records by year. Below the procedure that has been developed DECLARE l_year VARCHAR2 (4

  • My nokia 5300 keeps turning itself off

    Help my nokia 5300 keeps turning itself off. It won't let me read my messages. Everytime I press the key to read my messages it just goes off. I only had it about 6 months!!!