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
// 1. define a custom HttpClientFactory | |
public class VcrHttpClientFactory : DefaultHttpClientFactory | |
{ | |
private readonly string _cassette; | |
public VcrHttpClientFactory(string cassette) { | |
_cassette = cassette; | |
} | |
public override HttpMessageHandler CreateMessageHandler() { |
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
[Test] | |
public async Task StackOverflowQuestion() { | |
var message = ""; | |
try { | |
var cli = new FlurlClient("https://www.google.com").EnableCookies(); | |
var s = await cli.Request().GetStringAsync(); | |
var result = await cli.Request("foo").PostUrlEncodedAsync(new { x = "x" }); | |
} | |
catch (FlurlHttpException ex) { | |
message = ex.Message; |
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
// Do this in Startup. All calls to SimpleCast will use the same HttpClient instance. | |
FlurlHttp.ConfigureClient(Configuration["SimpleCastServiceUri"], cli => cli | |
.Configure(settings => | |
{ | |
// keeps logging & error handling out of SimpleCastClient | |
settings.BeforeCall = call => logger.LogWarning($"Calling {call.Request.RequestUri}"); | |
settings.OnError = call => logger.LogError($"Call to SimpleCast failed: {call.Exception}"); | |
}) | |
// adds default headers to send with every call | |
.WithHeaders(new |
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
public static class Throttler | |
{ | |
/// <summary> | |
/// Concurrently run a task for each data item. Like Task.WhenAll, except you can cap the number allowed to run at a time, | |
/// and enforce a minimum pause between the start of each. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="items">A list of data items.</param> | |
/// <param name="minPause">Minimum wait time in milliseconds between starting tasks.</param> | |
/// <param name="maxConcurrent">Maximum tasks allowed to run at the same time.</param> |
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
function copy-deployable-web-files($proj_path, $deploy_dir) { | |
# copy files where Build Action = "Content" | |
$proj_dir = split-path -parent $proj_path | |
[xml]$xml = get-content $proj_path | |
$xml.Project.ItemGroup | % { $_.Content } | % { $_.Include } | ? { $_ } | % { | |
$from = "$proj_dir\$_" | |
$to = split-path -parent "$deploy_dir\$_" | |
if (!(test-path $to)) { md $to } | |
cp $from $to | |
} |
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
var result = await "http://localhost:8080/lzp/servRoot" | |
.PostUrlEncodedAsync(new { | |
className = "com.lzp.service.UserInfoService", | |
methodName = "login", | |
user_name = "123", | |
user_pwd = "123" | |
}) | |
.ReceiveJson<TestResultModel>(); |
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.IO; | |
using Newtonsoft.Json; | |
namespace Flurl.Http.Configuration | |
{ | |
/// <summary> | |
/// ISerializer implementation based on Newtonsoft.Json. | |
/// Default serializer used in calls to GetJsonAsync, PostJsonAsync, etc. | |
/// </summary> | |
public class NewtonsoftJsonSerializer : ISerializer |