广告位管理系统--跨域广告加载问题

问题一:

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

文件: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中再次发送,具体打包那些数据看实际需求

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值