Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FormUrlEncodedContent.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
using
System.IO
;
3
using
System.Net.Http.Headers
;
4
using
System.Text
;
5
using
System.Threading
;
6
using
System.Threading.Tasks
;
7
8
namespace
System.Net.Http
;
9
10
public
class
FormUrlEncodedContent
:
ByteArrayContent
11
{
12
public
FormUrlEncodedContent
(
IEnumerable
<
KeyValuePair<string, string>
>
nameValueCollection
)
13
:
base
(
GetContentByteArray
(
nameValueCollection
))
14
{
15
base.Headers.ContentType =
new
MediaTypeHeaderValue
(
"application/x-www-form-urlencoded"
);
16
}
17
18
private
static
byte
[]
GetContentByteArray
(
IEnumerable
<
KeyValuePair<string, string>
>
nameValueCollection
)
19
{
20
if
(
nameValueCollection
==
null
)
21
{
22
throw
new
ArgumentNullException
(
"nameValueCollection"
);
23
}
24
StringBuilder
stringBuilder
=
new
StringBuilder
();
25
foreach
(
KeyValuePair<string, string>
item
in
nameValueCollection
)
26
{
27
if
(
stringBuilder
.Length > 0)
28
{
29
stringBuilder
.Append(
'&'
);
30
}
31
stringBuilder
.Append(
Encode
(
item
.Key));
32
stringBuilder
.Append(
'='
);
33
stringBuilder
.Append(
Encode
(
item
.Value));
34
}
35
return
HttpRuleParser
.
DefaultHttpEncoding
.GetBytes(
stringBuilder
.ToString());
36
}
37
38
private
static
string
Encode
(
string
data)
39
{
40
if
(
string
.IsNullOrEmpty(data))
41
{
42
return
string
.Empty;
43
}
44
return
Uri
.
EscapeDataString
(data).Replace(
"%20"
,
"+"
);
45
}
46
47
protected
override
Task
SerializeToStreamAsync
(
Stream
stream
,
TransportContext
? context,
CancellationToken
cancellationToken
)
48
{
49
if
(!(GetType() ==
typeof
(
FormUrlEncodedContent
)))
50
{
51
return
base
.SerializeToStreamAsync(
stream
, context,
cancellationToken
);
52
}
53
return
SerializeToStreamAsyncCore
(
stream
,
cancellationToken
);
54
}
55
56
internal
override
Stream
TryCreateContentReadStream
()
57
{
58
if
(!(GetType() ==
typeof
(
FormUrlEncodedContent
)))
59
{
60
return
null
;
61
}
62
return
CreateMemoryStreamForByteArray
();
63
}
64
}
System.ArgumentNullException
Definition
ArgumentNullException.cs:10
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.IO.Stream
Definition
Stream.cs:11
System.Net.Http.ByteArrayContent.SerializeToStreamAsyncCore
Task SerializeToStreamAsyncCore(Stream stream, CancellationToken cancellationToken)
Definition
ByteArrayContent.cs:65
System.Net.Http.ByteArrayContent.CreateMemoryStreamForByteArray
MemoryStream CreateMemoryStreamForByteArray()
Definition
ByteArrayContent.cs:95
System.Net.Http.ByteArrayContent
Definition
ByteArrayContent.cs:8
System.Net.Http.FormUrlEncodedContent.FormUrlEncodedContent
FormUrlEncodedContent(IEnumerable< KeyValuePair< string, string > > nameValueCollection)
Definition
FormUrlEncodedContent.cs:12
System.Net.Http.FormUrlEncodedContent.SerializeToStreamAsync
override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
Definition
FormUrlEncodedContent.cs:47
System.Net.Http.FormUrlEncodedContent.GetContentByteArray
static byte[] GetContentByteArray(IEnumerable< KeyValuePair< string, string > > nameValueCollection)
Definition
FormUrlEncodedContent.cs:18
System.Net.Http.FormUrlEncodedContent.Encode
static string Encode(string data)
Definition
FormUrlEncodedContent.cs:38
System.Net.Http.FormUrlEncodedContent.TryCreateContentReadStream
override Stream TryCreateContentReadStream()
Definition
FormUrlEncodedContent.cs:56
System.Net.Http.FormUrlEncodedContent
Definition
FormUrlEncodedContent.cs:11
System.Net.Http.Headers.MediaTypeHeaderValue
Definition
MediaTypeHeaderValue.cs:9
System.Net.Http.HttpRuleParser.DefaultHttpEncoding
static Encoding DefaultHttpEncoding
Definition
HttpRuleParser.cs:9
System.Net.Http.HttpRuleParser
Definition
HttpRuleParser.cs:6
System.Net.TransportContext
Definition
TransportContext.cs:6
System.Text.StringBuilder
Definition
StringBuilder.cs:14
System.Threading.Tasks.Task
Definition
Task.cs:14
System.Uri.EscapeDataString
static string EscapeDataString(string stringToEscape)
Definition
Uri.cs:4087
System.Uri
Definition
Uri.cs:16
System.Collections.Generic.IEnumerable
Definition
IEnumerable.cs:4
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.IO
Definition
ConsoleStream.cs:3
System.Net.Http.Headers
Definition
AltSvcHeaderParser.cs:4
System.Net.Http
Definition
HttpClientJsonExtensions.cs:8
System.Text
Definition
ConsoleEncoding.cs:1
System.Threading.Tasks
Definition
TaskToApm.cs:3
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.item
@ item
System.ExceptionArgument.cancellationToken
@ cancellationToken
System.ExceptionArgument.stream
@ stream
System.Threading.CancellationToken
Definition
CancellationToken.cs:8
source
System.Net.Http
System.Net.Http
FormUrlEncodedContent.cs
Generated by
1.10.0