0

I am trying to send a string with a POST request. enter image description here

however when I do this the parameter is still null enter image description here

IOEnthusiast
  • 105
  • 6
  • You can try write a class that contains message property. Then, create an instance of the class and set the message property equals "Message" value. Then pass the object instead of "Message" value like this, var a = new A(); a.message = "Message"; await Client.PostAsJsonAsync(address, a); – Vecihi Baltacı Sep 19 '22 at 08:02
  • Yes,I have found such examples,but I hoped there were better solutions for when only one parameter has to be sent. – IOEnthusiast Sep 19 '22 at 08:04
  • 1
    Please don't post images of code. Post code as text instead – Bill Tür stands with Ukraine Sep 19 '22 at 08:06
  • see this SO [answer](https://stackoverflow.com/a/23586477/14973743) to send JSON as payload using HttpClient. just sending "message" as shown by you doesn't send json. – Anand Sowmithiran Sep 19 '22 at 08:11

1 Answers1

0

For a simple scenario, you can pass the parameter in the URL with PostAsync() method. You don't need to create an extra object or anything

await httpClient.PostAsync("https://localhost:60500/LogInfo?message=Test message", null);

Not sure if this is a good idea, but you can check another question here HTTP POST with URL query parameters -- good idea or not?

T. Dominik
  • 406
  • 3
  • 13