简体   繁体   English

如何使用 C# 客户端以字符串作为参数发送 post 请求

[英]How to send a post request with the C# client with a string as a parameter

I am trying to send a string with a POST request.我正在尝试使用 POST 请求发送字符串。 在此处输入图像描述

however when I do this the parameter is still null但是当我这样做时,参数仍然是 null 在此处输入图像描述

For a simple scenario, you can pass the parameter in the URL with PostAsync() method.对于一个简单的场景,您可以使用PostAsync()方法传递 URL 中的参数。 You don't need to create an extra object or anything您不需要创建额外的 object 或任何东西

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?不确定这是否是一个好主意,但您可以在此处查看另一个问题HTTP POST with URL 查询参数——好主意与否?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM