0

I have ASPX page where I store images. The URL for these images are around 2000 characters.

The value of this URL is read from somewhere and I don't have control.

I would like to know if anyone has handled these type of situation.

I have a javascript procedure that reconstructs this URL.

so I would like to know,

a) How to handle URLs that are longer in length. (I get the URL in OnInit). Since they are longer, I would like to use javascript function that will trim the URL length.

b) Once I get the reconstructed URL (which will be around 500 characters) I want to assign this back to the image and allow the page loading to complete. To achieve

Thanks in advance,

Update 0 : I would like to know how httpwebrequest can be used to post an image in the same post??

Update 1: I have updated my original post.

Update 2 Javascript code. This code reconstructions and the submits the document. I am fine with using this javascript as it is OR I can just the modified URL and then assign it to the image in my code-behind (OnInit).

<script type="text/javascript">
function posturl(url) {
    var qsBegin = url.indexOf("?");
    var qsPattern = new RegExp("[?&]([^=]*)=([^&]*)", "ig");
    var match = qsPattern.exec(url);
    var params = new Array();

    while (match != null) {
        var matchID = match[1];
        if ( matchID.charAt(0) == "&" ) {
            matchID = matchID.substr(1);
        }

        if ( params[match[1]] != null && !(params[match[1]] instanceof Array) ) {
            var subArray = new Array();
            subArray.push(params[match[1]]);
            subArray.push(unescape(match[2]));
            params[match[1]] = subArray;
        } else if ( params[match[1]] != null && params[match[1]] instanceof Array ) {
            params[match[1]].push(unescape(match[2]));
        } else {
            params[match[1]]=unescape(match[2]);
        }   
        match = qsPattern.exec(url);
    }

    var myForm = document.createElement("form");
    myForm.setAttribute("target", "_blank");
    myForm.method="post" ;
    myForm.action = url.substring(0,qsBegin) ;
    for (var k in params) {
        var myInput;
        // Check for params with the same name.
        if ( params[k] instanceof Array ) {
            for ( var i=0; i<params[k].length; i++ ) {
                myInput = createFormInput(k, params[k][i]);
                myForm.appendChild(myInput) ;
            }
        } else {
            myInput = createFormInput(k, params[k]);
            myForm.appendChild(myInput);
        }
    }

    document.body.appendChild(myForm) ;
    myForm.submit() ;
    document.body.removeChild(myForm) ;
}
Anirudh
  • 581
  • 5
  • 14
  • 32
  • 1
    URLs in excess of 2000 characters are not well supported, see http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url. – Jeremy Holovacs May 29 '12 at 13:59
  • @JeremyHolovacs: Since the URL length is an issue, I would like to use a javascript function. I have been not able to get success with the javascript function so far. I will paste that javascript in my original post. – Anirudh May 29 '12 at 14:04
  • @SalmanA: I am trying to reconstruct the URL at this point. Getting into some issues. – Anirudh May 29 '12 at 14:05
  • Is it (really) a url or the image data (base64) itself? – EdSF May 29 '12 at 14:34
  • @EdSF: Well the URL is longer but I have a javascript routine to reconstruct. Once I get reconstructed URL, I would like to use http post on the image such that is shown when the page is submitted or displayed. – Anirudh May 29 '12 at 14:40

1 Answers1

1

The problem is not in the length of what the protocal can handle, but in the length your client can handle. Most browser have a max get size about 2000 chars. If you want more you need an other browser. However that is normally not under your control.

The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).

Note: Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.

You can try to use a post to send the information to the server and return the image to you client.

Peter
  • 27,590
  • 8
  • 64
  • 84
  • Thanks for the input. I would like to use POST and I need more inputs. CAn you provide the same considering my scenario mentioned above? – Anirudh May 29 '12 at 14:09
  • I would like to know how httpwebrequest can be used to post an image in the same post?? – Anirudh May 29 '12 at 14:39
  • Anyone can suggest me? Don't know if question is very basic? or complex? – Anirudh May 29 '12 at 16:14