ASP.NET-& gt;有人处理过超过2500个字符的图片Urls吗? [英] ASP.NET -> Has anyone dealt with image Urls that are over 2500 characters?

查看:94
本文介绍了ASP.NET-& gt;有人处理过超过2500个字符的图片Urls吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于存储图像的ASPX页面.这些图片的网址大约为2000个字符.

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

此URL的值是从某个地方读取的,我无法控制.

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.

我有一个可重构此URL的Javascript过程.

I have a javascript procedure that reconstructs this URL.

所以我想知道

a)如何处理长度较长的URL.(我在OnInit中获得了URL).由于它们较长,因此我想使用可调整URL长度的javascript函数.

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)一旦获得重构的URL(大约500个字符),我想将其分配回图像并允许页面加载完成.实现

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

预先感谢

更新0:我想知道如何使用httpwebrequest在同一帖子中发布图像?

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

更新1:我已经更新了我的原始帖子.

Update 1: I have updated my original post.

更新2 JavaScript代码.此代码重建并提交文件.我可以使用此javascript,因为我可以使用它,也可以,也可以只修改后的URL,然后将其分配给代码隐藏(OnInit)中的图像.

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) ;
}

推荐答案

问题不在于协议可以处理的长度,而在于客户可以处理的长度.大多数浏览器的最大获取大小约为2000个字符.如果您想要更多,则需要其他浏览器.但是,通常这不受您的控制.

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.

HTTP协议没有对长度限制进行任何先验限制URI.服务器必须能够处理其任何资源的URI服务,并且应该能够处理长度不受限制的URI提供可以生成此类URI的基于GET的表单.服务器应该如果URI的长度比URI的长度长,则返回414(请求URI太长)状态服务器可以处理(请参阅10.4.15节).

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).

注意:服务器应根据URI的长度谨慎行事255字节以上,因为某些较旧的客户端或代理实现可能无法正确支持这些长度.

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.

这篇关于ASP.NET-&amp; gt;有人处理过超过2500个字符的图片Urls吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆