MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/q5v3d7/whats_a_post_request/
r/badcode • u/Wide_Wish_1521 • Oct 11 '21
7 comments sorted by
6
Better make that HttpClient a singleton, or you'll get port exhaustion if you call that repeatedly.
5 u/Wide_Wish_1521 Oct 13 '21 I don't think this will be a problem. The code broke because the url with the base64 encoded json got too long 5 u/Rakn Oct 14 '21 Well better split it up an do two requests then.
5
I don't think this will be a problem. The code broke because the url with the base64 encoded json got too long
5 u/Rakn Oct 14 '21 Well better split it up an do two requests then.
Well better split it up an do two requests then.
7
Serialization is for suckers, apparently.
Image Transcription: Code
string erzeugenJson = @"{ ""Anwendung"": "Anwendung"", ""Version"": 1, ""Token"": ""12341234123412341234"", ""Email"": ""1234@1234.com"", ""Parameter"": [{""Spalte"": ""KDNR"", ""Wet"": "#KDNR""}, {""Spalte"": ""MODUL"", ""Wet"": "#MODUL""}, {""Spalte"": ""PROGRAMMTYP"", ""Wet"": "#PROGRAMMTYP""}, {""Spalte"": ""PROGRAMM"", ""Wet"": "#PROGRAMM""}, {""Spalte"": ""VERSION"", ""Wet"": "#VERSION""}, {""Spalte"": ""PRIORITAET"", ""Wet"": "#PRIORITAET""}, {""Spalte"": ""BESCHREIBUNG"", ""Wet"": "#BESCHREIBUNG""}] }"; int? kdnr = null; if (dt.Rows.Count != 0) { kdnr = Convert.ToInt32(dt.Rows[0]["KDNR"]); } var replacedJson = erzeugenJson.replace("#KDNR", kdnr.ToString()) .Replace("#MODUL", Modul) .Replace("#PROGRAMMTYP", Programmtyp) .Replace("#PROGRAMM", Programm) .Replace("#VERSION", Version) .Replace("#PRIORITAET", Meldungstyp) .Replace("#BESCHREIBUNG", Beschreibung.Replace("\"", string.Empty).Replace(Environment.NewLine, " ")); //Bytearray von dem String erstellen und in BASE64 Codieren. var bytes = Encoding.UTF8.GetBytes(replacedJson); var jsonstring = Convert.ToBase64String(bytes); HttpClient Client = new HttpClient() { Timeout = new TimeSpan(0, 0, 0, 10, 0) }; HttpWebREquest request = (HttpWebRequest)WebRequest.Create(new Uri(erzeugenUri + jsonString)); request.Method = "GET"; request.ContentType = "application/json"; try { var erg = Client.GetStringAsync(request.RequestUri); var result = erg.Result; if (!result.Contains("\"TR\":\"OK\"")) { MessageBox.Show("Es ist ein Fehler aufgetreten."); return; } TicketNummer = Convert.ToInt32(result.Split(',')[3].Split(':')[1].Replace("\"", "").Trim('}')); } catch (Exception ex) {
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
4
That like… one way to do it. Yes…
3
Also: What is a status code?
6
u/[deleted] Oct 11 '21
Better make that HttpClient a singleton, or you'll get port exhaustion if you call that repeatedly.
7
u/OfficerFuttBuck Oct 11 '21
Serialization is for suckers, apparently.
6
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 11 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
4
u/Rakn Oct 14 '21
That like… one way to do it. Yes…
3
u/notBjoern Oct 24 '21
Also: What is a status code?