Last active
May 8, 2018 23:09
-
-
Save z3nth10n/7a2574da2ce7f3afec4edfc1af1c5478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Flurl.Http; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
namespace DotNetAssembly | |
{ | |
internal static class FlurlExtensions | |
{ | |
public static string HttpPost(this string url, object data) | |
{ | |
return url.PostUrlEncodedAsync(data).ReceiveString().GetAwaiter().GetResult(); | |
} | |
public static string HttpGet(this string url) | |
{ | |
return url.GetStringAsync().GetAwaiter().GetResult(); | |
} | |
public static string HttpPost(this FlurlClient client, string url, object data) | |
{ | |
return client.Request(url).PostUrlEncodedAsync(data).ReceiveString().GetAwaiter().GetResult(); | |
} | |
public static string HttpGet(this FlurlClient client, string url) | |
{ | |
return client.WithCookies(client.Cookies).Request(url).GetStringAsync().GetAwaiter().GetResult(); | |
} | |
private static string AnonymousToQS(this object data) | |
{ | |
Type type = data.GetType(); | |
PropertyInfo[] props = type.GetProperties(); | |
IEnumerable<string> pairs = props.Select(x => x.Name + "=" + x.GetValue(data, null)).ToArray(); | |
return string.Join("&", pairs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment