当前位置: 首页>>代码示例>>C#>>正文


C# Header.Replace方法代码示例

本文整理汇总了C#中Header.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# Header.Replace方法的具体用法?C# Header.Replace怎么用?C# Header.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Header的用法示例。


在下文中一共展示了Header.Replace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Document

        public Document(Kernel kernel, Logger logger, Conf conf, SockTcp tcpObj, ContentType contentType)
        {
            //this.kernel = kernel;
            _logger = logger;
            //_oneOption = oneOption;
            _conf = conf;
            _sockTcp = tcpObj;
            _contentType = contentType;

            SetRangeTo = false;

            //���M�w�b�_������
            _sendHeader = new Header();
            _sendHeader.Replace("Server", Util.SwapStr("$v", kernel.Ver.Version(), (string)_conf.Get("serverHeader")));
            _sendHeader.Replace("MIME-Version","1.0");
            _sendHeader.Replace("Date",Util.UtcTime2Str(DateTime.UtcNow));

            _body = new Body();
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:19,代码来源:Document.cs

示例2: TotalTest

        public void TotalTest()
        {
            const int max = 5;
            var sb = new StringBuilder();
            for (int i = 0; i < max; i++) {
                sb.Append(string.Format("key_{0:D3}: val_{0:D3}\r\n", i));
            }
            byte [] buf = Bytes.Create(sb.ToString());
            var header = new Header(buf);

            //GetBytes()
            //自動的に追加される空行を追加すると、初期化したbyte[]と同じになるはず
            var tmp = Bytes.Create(header.GetBytes(),"\r\n");
            for (int i=0;i<buf.Length;i++) {
                Assert.AreEqual(buf[i],tmp[i]);
            }

            //Count
            Assert.AreEqual(header.Count,max);

            for(var i=0;i<header.Count;i++){
                var key = string.Format("key_{0:D3}",i);
                var valStr = string.Format("val_{0:D3}",i);

                //GetVal(string key)
                Assert.AreEqual(header.GetVal(key), valStr);

                //Replace(string key,string str)
                var replaceStr = string.Format("replace_{0:D3}",i);
                header.Replace(key,replaceStr);
                Assert.AreEqual(header.GetVal(key), replaceStr);
            }

            const int appendMax = 3;
            for (int i = 0; i < appendMax; i++) {
                //Append(string key,string val)
                var key = string.Format("AppendKey_{0:D3}", i);
                var val = string.Format("AppendVal_{0:D3}", i);
                header.Append(key, Encoding.ASCII.GetBytes(val));
                //string s = header.GetVal(key);
                Assert.AreEqual(header.GetVal(key), val);
            }
            Assert.AreEqual(header.Count, max + appendMax);
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:44,代码来源:HeaderTest.cs

示例3: Pipe


//.........这里部分代码省略.........
                Proxy.Sock(CS.Server).AsciiSend("PWD");
                if (!WaitLine("257", ref paramStr, iLife))
                    return false;
                var tmp = paramStr.Split(' ');
                if (tmp.Length >= 1) {
                    _path = tmp[0].Trim(new[] { '"' });
                    if (_path[_path.Length - 1] != '/') {
                        _path = _path + "/";
                    }
                }
            }

            //リクエスト
            if(_path != "") {
                Proxy.Sock(CS.Server).AsciiSend(string.Format("CWD {0}",_path));
                if (!WaitLine("250", ref paramStr,iLife))
                    goto end;
            }

            Proxy.Sock(CS.Server).AsciiSend(_file == "" ? "TYPE A" : "TYPE I");
            if (!WaitLine("200", ref paramStr,iLife))
                goto end;

            //PORTコマンド送信
            var bindAddr = Proxy.Sock(CS.Server).LocalIp;
            // 利用可能なデータポートの選定
            while (iLife.IsLife()){
                DataPort++;
                if (DataPort >= 9999) {
                    DataPort = 2000;
                }
                if (SockServer.IsAvailable(_kernel,bindAddr, DataPort)){
                    break;
                }
            }
            int listenPort = DataPort;

            //データスレッドの生成
            dataThread = new DataThread(_kernel,bindAddr,listenPort);

            // サーバ側に送るPORTコマンドを生成する
            string str = string.Format("PORT {0},{1},{2},{3},{4},{5}", bindAddr.IpV4[0], bindAddr.IpV4[1], bindAddr.IpV4[2], bindAddr.IpV4[3], listenPort / 256, listenPort % 256);

            Proxy.Sock(CS.Server).AsciiSend(str);
            if (!WaitLine("200", ref paramStr, iLife))
                goto end;

            if(_file == "") {
                Proxy.Sock(CS.Server).AsciiSend("LIST");
                if (!WaitLine("150", ref paramStr, iLife))
                    goto end;
            } else {
                Proxy.Sock(CS.Server).AsciiSend("RETR " + _file);
                if (!WaitLine("150", ref paramStr, iLife))
                    goto end;

            }

            //Ver5.0.2
            while(iLife.IsLife()) {
                if(!dataThread.IsRecv)
                    break;
            }

            if (!WaitLine("226", ref paramStr,iLife))
                goto end;

            byte[] doc;
            if(_file == "") {
                //受信結果をデータスレッドから取得する
                List<string> lines = Inet.GetLines(dataThread.ToString());
                //FTPサーバから取得したLISTの情報をHTMLにコンバートする
                doc = ConvFtpList(lines,_path);
            } else {
                doc = dataThread.ToBytes();
            }

            //クライアントへリプライ及びヘッダを送信する
            var header = new Header();
            header.Replace("Server", Util.SwapStr("$v", _kernel.Ver.Version(),(string)_conf.Get("serverHeader")));

            header.Replace("MIME-Version","1.0");

            if(_file == "") {
                header.Replace("Date",Util.UtcTime2Str(DateTime.UtcNow));
                header.Replace("Content-Type","text/html");
            } else {
                header.Replace("Content-Type","none/none");
            }
            header.Replace("Content-Length",doc.Length.ToString());

            Proxy.Sock(CS.Client).AsciiSend("HTTP/1.0 200 OK");//リプライ送信
            Proxy.Sock(CS.Client).SendUseEncode(header.GetBytes());//ヘッダ送信
            Proxy.Sock(CS.Client).SendNoEncode(doc);//ボディ送信
            end:
            if(dataThread != null)
                dataThread.Dispose();

            return false;
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:101,代码来源:ProxyFtp.cs

示例4: PipeFtp


//.........这里部分代码省略.........

            sock[CS.SERVER].AsciiSend(string.Format("USER {0}",user),OPERATE_CRLF.YES);
            if(!WaitLine(sock,"331"))
                goto end;

            sock[CS.SERVER].AsciiSend(string.Format("PASS {0}",pass),OPERATE_CRLF.YES);
            if(!WaitLine(sock,"230"))
                goto end;

            //URIをパスとファイル名に分解する
            string path = request.Uri;
            string file = "";
            int index = request.Uri.LastIndexOf('/');
            if (index < request.Uri.Length - 1) {
                path = request.Uri.Substring(0, index);
                file = request.Uri.Substring(index + 1);
            }

            //リクエスト
            if (path != "") {
                sock[CS.SERVER].AsciiSend(string.Format("CWD {0}",path),OPERATE_CRLF.YES);
                if (!WaitLine(sock, "250"))
                    goto end;
            }

            if (file == "") {
                sock[CS.SERVER].AsciiSend("TYPE A",OPERATE_CRLF.YES);
            } else {
                sock[CS.SERVER].AsciiSend("TYPE I",OPERATE_CRLF.YES);
            }
            if(!WaitLine(sock,"200"))
                goto end;

            //PORTコマンド送信
            Ip bindAddr = new Ip(sock[CS.SERVER].LocalEndPoint.Address.ToString());
            // 利用可能なデータポートの選定
            int listenMax = 1;
            SSL ssl = null;
            TcpObj listenObj=null;
            while(life){
                listenObj = new TcpObj(kanel, this.Logger,bindAddr, dataPort++, listenMax, ssl);
                if (listenObj.State != SOCKET_OBJ_STATE.ERROR)
                    break;
            }
            if(listenObj==null)
                goto end;

            //データスレッドの生成
            dataThread = new DataThread(this.Logger, listenObj);

            // サーバ側に送るPORTコマンドを生成する
            string str = string.Format("PORT {0},{1},{2},{3},{4},{5}",bindAddr.IpV4[0],bindAddr.IpV4[1],bindAddr.IpV4[2],bindAddr.IpV4[3],(listenObj.LocalEndPoint.Port) / 256,(listenObj.LocalEndPoint.Port) % 256);
            sock[CS.SERVER].AsciiSend(str,OPERATE_CRLF.YES);
            if(!WaitLine(sock,"200"))
                goto end;

            if(file==""){
                sock[CS.SERVER].AsciiSend("LIST",OPERATE_CRLF.YES);
                if(!WaitLine(sock,"150"))
                    goto end;
            }else{
                sock[CS.SERVER].AsciiSend("RETR " + file,OPERATE_CRLF.YES);
                if(!WaitLine(sock,"150"))
                    goto end;

            }
            if(!WaitLine(sock,"226"))
                goto end;

            byte[] doc = new byte[0];
            if (file == "") {
                //受信結果をデータスレッドから取得する
                List<string> lines = Inet.GetLines(dataThread.ToString());
                //FTPサーバから取得したLISTの情報をHTMLにコンバートする
                doc = ConvFtpList(lines, path);
            } else {
                doc = dataThread.ToBytes();
            }

            //クライアントへリプライ及びヘッダを送信する
            Header header = new Header();
            header.Replace("Server",Util.SwapStr("$v",kanel.Ver.Version(),this.OpBase.ValString("serverHeader")));
            header.Replace("MIME-Version","1.0");
            if (file == "") {
                header.Replace("Date",Util.UtcTime2Str(DateTime.UtcNow));
                header.Replace("Content-Type","text/html");
            } else {
                header.Replace("Content-Type","none/none");
            }
            header.Replace("Content-Length",doc.Length.ToString());

            sock[CS.CLIENT].AsciiSend("HTTP/1.0 200 OK",OPERATE_CRLF.YES);//リプライ送信
            sock[CS.CLIENT].Send(header.GetBytes());//ヘッダ送信
            sock[CS.CLIENT].Send(doc);//ボディ送信
            end:
            if (dataThread != null)
                dataThread.Dispose();

            return dataPort;
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:101,代码来源:Server.HTTP1.0.cs


注:本文中的Header.Replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。