zoukankan      html  css  js  c++  java
  • 广告位管理系统跨域广告加载问题

    问题一:

    跨域采用服务器代理页来中转,请求转投代码如下:

    文件:Ad.ashx

    //================代理实现=============================

        private void RequestProxy()
        {
     
            HttpWebRequest clientRequest = (HttpWebRequest)HttpWebRequest.Create(C_URL + Request.Url.Query);
            clientRequest.AllowAutoRedirect = false;
            clientRequest.Method = Request.RequestType;
            int bufferSize = 1024 * 2;
            byte[] buffer = new byte[bufferSize];
            if (Request.RequestType == "POST")
            {
                clientRequest.ContentType = Request.ContentType;
                clientRequest.ContentLength = Request.ContentLength;
                using (Stream postStream = clientRequest.GetRequestStream())
                {
                    postStream.Write(Request.BinaryRead(Request.TotalBytes), 0, Request.TotalBytes);
                }
            }
            //输出数据
            using (HttpWebResponse clientResponse = clientRequest.GetResponse() as HttpWebResponse)
            {
                Response.ContentType = clientResponse.ContentType;
           
                using (Stream stream = clientResponse.GetResponseStream())
                {
                    int readCount = stream.Read(buffer, 0, bufferSize);
                    while (readCount > 0)
                    {
                        Response.OutputStream.Write(buffer, 0, readCount);
                        readCount = stream.Read(buffer, 0, bufferSize);
                    }

                }
            }
        
           
        }

    //===================End==============

    问题二:

    需要在广告的OnClick事件中记录广告位的点击情况

    采用Jquery的$.post来发送onclick相关数据,js代码如下(网站采用gb2312)

    $.post("/services/ad.ashx?m=1",{msg:escape( '数据中包含中文需要采用escape编码'),OtherField:'value'});

    服务器需要使用 HttpUtility.UrlDecode(  Request["msg"],Encoding.GetEncoding("GB2312"))来解码,UrlDecode的Encoding可以指定是GB2312或者Utf-8,结果都是正确的,因为escape在客户端对中文编码后,无论页面使用的是Utf-8还是GB2312其escpae('中文数据') 结果都是一样的,调用$.post会再次使用url编码数据,结果是可表示成-> form:urlEncode( js:escpae('中问数据'))

    而escpae后的ASCII字符无论utf-8或GB2312的form:UrlEncode编码多是一样的(注意,JQuery.post采用utf-8对数据进行编码), Request["msg"] 会对数据进行一次解码,而解码后的数据是escape的结果,故还需要使用一次HttpUtility.UrlDecode(....)再次解码--asp.net中的UrlDecode可以解码js的escape编码数据。

    ------------------------------------

    问题三:

    采用代理页后客户端的一些信息如IP等,需要打包到url中再次发送,具体打包那些数据看实际需求

  • 相关阅读:
    window phone7中自定义listbox或scrollviewer滚动条样式
    windows phone7中使用bing中文地图和Google地图
    window phone7中listbox,ItemsControl等项渲染速度慢的解决方案
    window phone list box使用收藏,mvvm ItemsControl数据绑定
    RSA的密钥把JAVA格式转换成C#的格式
    自定义控件
    【03】flask之url_for函数及过滤器使用
    【01】flask之入门及安装
    js 弹出层
    插入排序_排序算法_算法
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1770091.html
Copyright © 2011-2022 走看看