Kein
Kein
CC#
Created by Kein on 11/20/2023 in #help
Extending custom WPF control
No description
2 replies
CC#
Created by Kein on 10/19/2023 in #help
❔ Skipping null values in .NET XML serializer
I have data class with 113 properties. I want to skip serializing null value, including Nullable value types like int Am I still destined to write all 113 public bool ShouldSerializeMyNullableProp1,2,3,4,5...() for this in the year of our Lord 2023?
2 replies
CC#
Created by Kein on 4/19/2023 in #help
❔ Splittings UT8 text
2 replies
CC#
Created by Kein on 4/17/2023 in #help
❔ HTTPclient fails to POST properly
Target website has a very basic login form, and I have no problems logging in via curl:
curl1 -vv -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" -H "Referer: https://www.website.com/session/login" --cookie "PHPSESSID=ehoj1hg8daist388b72k8c2roe" -d "OWhVNUhsOE5ZS2ZIc1hWdWtiZ05pUT09=ZFoyZjBjeWJzTWJMdjkwQWVndlQyUT09&email=my%40mail.com&password=12345" -o N:/login.html https://www.website.com/session/login
curl1 -vv -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" -H "Referer: https://www.website.com/session/login" --cookie "PHPSESSID=ehoj1hg8daist388b72k8c2roe" -d "OWhVNUhsOE5ZS2ZIc1hWdWtiZ05pUT09=ZFoyZjBjeWJzTWJMdjkwQWVndlQyUT09&email=my%40mail.com&password=12345" -o N:/login.html https://www.website.com/session/login
However, attempt to sent POST with HttpClient always fails:
const string baseURL = @"https://www.website.com";
HttpClient client = new HttpClient();
client.Timeout = new TimeSpan(0, 0, 30);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
//---
// Parsing CRSF tokens and PHPSESSID from first pass
//---
client.DefaultRequestHeaders.Add("Cookie", phpSession);
var credentials = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>(match.Groups[1].Value, match.Groups[2].Value),
new KeyValuePair<string,string>("email", "[email protected]"),
new KeyValuePair<string,string>("password", "12345"),
});
var req = new HttpRequestMessage(HttpMethod.Post, $"{baseURL}/session/login") { Content = credentials };
const string baseURL = @"https://www.website.com";
HttpClient client = new HttpClient();
client.Timeout = new TimeSpan(0, 0, 30);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
//---
// Parsing CRSF tokens and PHPSESSID from first pass
//---
client.DefaultRequestHeaders.Add("Cookie", phpSession);
var credentials = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>(match.Groups[1].Value, match.Groups[2].Value),
new KeyValuePair<string,string>("email", "[email protected]"),
new KeyValuePair<string,string>("password", "12345"),
});
var req = new HttpRequestMessage(HttpMethod.Post, $"{baseURL}/session/login") { Content = credentials };
The response should be 302 Found and then response header contain redirect to profile location, but I'm not getting it. I do get it with curl tho. So the issue is with Httpclient. Any idea what cold be the differences between curl and HttpClient that make the former work?
39 replies
CC#
Created by Kein on 1/10/2023 in #help
❔ Pinging hundred of hosts sequentially
I'm getting weird inconsistent results:
Ping pingSender = new Ping();
PingOptions options = new PingOptions(128, false);
for (int i = 0; i < data.Count; i++)
{
var sessRes = data[i];
var reply = pingSender.Send(sessRes.HostAddress, 1000, filler, options);
if (reply.Status == IPStatus.Success)
sessRes.Ping = (uint)reply.RoundtripTime;
Thread.Sleep(100);
}
Ping pingSender = new Ping();
PingOptions options = new PingOptions(128, false);
for (int i = 0; i < data.Count; i++)
{
var sessRes = data[i];
var reply = pingSender.Send(sessRes.HostAddress, 1000, filler, options);
if (reply.Status == IPStatus.Success)
sessRes.Ping = (uint)reply.RoundtripTime;
Thread.Sleep(100);
}
I know for a fact that among all the host addresses none of them exceed ping above 300ms and they ALL respond to ICMP yet I'm getting almost half as TimedOut. Any idea what gives? This work already offloaded to separate Task so I dont need async version. If you know more reliable tools to ping dozens of hosts that would work too.
4 replies