-
-
Save robertkraig/9012b1bb870a556902c1505467aa2a6f to your computer and use it in GitHub Desktop.
This file contains 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 System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using System.Collections.Specialized; | |
class DataService { | |
public NameValueCollection Query { get; set; } | |
public string Endpoint { get; set; } | |
public FormUrlEncodedContent QueryEncoded { | |
get { | |
try { | |
return new FormUrlEncodedContent( Query.AllKeys | |
.Select( s => new { Key = s, Value = Query[s] } ) | |
.ToDictionary( p => p.Key, p => p.Value ) ); | |
} catch { | |
return null; | |
} | |
} | |
} | |
public DataService() { | |
Query = new NameValueCollection(); | |
} | |
public void ClearQuery() { | |
Query.Clear(); | |
} | |
public async Task<string> Post() { | |
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; | |
string result = ""; | |
using( HttpClient client = new HttpClient() ) { | |
HttpResponseMessage reply = await client.PostAsync( Endpoint, QueryEncoded ); | |
result = await reply.Content.ReadAsStringAsync(); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment