Added ReadAsForm to the RequestExtensions to help with reading form data. Bumped package verison to 1.6.0
This commit is contained in:
@@ -97,5 +97,24 @@ namespace MontoyaTech.Rest.Net
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the content of a HttpListenerRequest as http form data and returns it as a dictionary. Any duplicate keys are ignored.
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns>A dictionary of keyvalue pairs from the form data.</returns>
|
||||
public static Dictionary<string, string> ReadAsForm(this HttpListenerRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var input = request.InputStream)
|
||||
using (var stream = new StreamReader(input))
|
||||
return stream.ReadToEnd().Trim().Split('&').Where(value => value.Contains('=')).ToLookup(value => value.Split('=')[0].Trim(), value => value.Split('=')[1].Trim()).ToDictionary(group => group.Key, group => group.FirstOrDefault());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<Version>1.5.9</Version>
|
||||
<Version>1.6.0</Version>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||
</PropertyGroup>
|
||||
|
Reference in New Issue
Block a user