本文整理汇总了C#中WebHeaderCollection.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# WebHeaderCollection.GetKey方法的具体用法?C# WebHeaderCollection.GetKey怎么用?C# WebHeaderCollection.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebHeaderCollection
的用法示例。
在下文中一共展示了WebHeaderCollection.GetKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpRequestHeader_GetKey_Success
public void HttpRequestHeader_GetKey_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
Assert.NotEmpty(w.GetKey(0));
}
示例2: GetKey_Fail
public void GetKey_Fail()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("Accept", "text/plain");
Assert.Throws<ArgumentOutOfRangeException>(() => w.GetKey(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => w.GetKey(42));
}
示例3: GetKey_Success
public void GetKey_Success()
{
const string key = "Accept";
const string key2 = "Content-Length";
WebHeaderCollection w = new WebHeaderCollection();
w.Add(key, "text/plain");
w.Add(key2, "123");
Assert.Equal(key, w.GetKey(0));
Assert.Equal(key2, w.GetKey(1));
}
示例4: ExecRequest
public Hashtable ExecRequest( string Cmd, string ContentType,
string Content, WebHeaderCollection hds,
bool GetResponse )
{
byte [] buf;
string line;
string req = String.Format(
"{0} {1} RTSP/1.0\r\n" + "CSeq: {2}\r\n",
Cmd, url, ++cseq );
if( session != null )
req += String.Format( "Session: {0}\r\n", session );
if( hds != null )
{
for( int i = 0; i < hds.Count; i++ )
{
req += String.Format( "{0}: {1}\r\n",
hds.GetKey( i ), hds.Get( i ) );
}
}
if( ContentType != null && Content != null )
{
req += String.Format(
"Content-Type: {0}\r\n" + "Content-Length: {1}\r\n",
ContentType, Content.Length );
}
req += String.Format( "User-Agent: {0}\r\n", useragent );
for( int i = 0; i < addheaders.Count; i++ )
{
req += String.Format( "{0}: {1}\r\n",
addheaders.GetKey( i ), addheaders.Get( i ) );
}
req += "\r\n";
if( ContentType != null && Content != null )
req += Content;
buf = Encoding.ASCII.GetBytes( req );
nsctrl.Write( buf, 0, buf.Length );
if( !GetResponse )
return null;
line = srctrl.ReadLine();
if( line == null || line == "" )
throw new Exception( "Request failed, read error" );
string [] tokens = line.Split( new char[] { ' ' } );
if( tokens.Length != 3 || tokens[ 1 ] != "200" )
throw new Exception( "Request failed, error " + tokens[ 1 ] );
string name = null;
Hashtable ht = new Hashtable();
while( ( line = srctrl.ReadLine() ) != null && line != "" )
{
if( name != null && Char.IsWhiteSpace( line[ 0 ] ) )
{
ht[ name ] += line;
continue;
}
int i = line.IndexOf( ":" );
if( i == -1 )
throw new Exception( "Request failed, bad header" );
name = line.Substring( 0, i );
ht[ name ] = line.Substring( i + 1 ).Trim();
}
return ht;
}