在 C# 中使用 WebClient.DownloadString 发送 POST
我知道关于使用 C# 发送 HTTP POST 请求存在很多问题,但我正在寻找一种使用 WebClient
而不是 HttpWebRequest
的方法。这可能吗?那就太好了,因为 WebClient
类非常易于使用。
我知道我可以设置 Headers
属性来设置某些标头,但我不知道是否可以实际从 WebClient
执行 POST。
I know there are a lot of questions about sending HTTP POST requests with C#, but I'm looking for a method that uses WebClient
rather than HttpWebRequest
. Is this possible? It'd be nice because the WebClient
class is so easy to use.
I know I can set the Headers
property to have certain headers set, but I don't know if it's possible to actually do a POST from WebClient
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用使用 HTTP POST 的
WebClient.UploadData()
,即:您指定的有效负载数据将作为请求的 POST 正文传输。
或者,可以使用
WebClient.UploadValues()
上传名称-值收集也通过 HTTP POST。You can use
WebClient.UploadData()
which uses HTTP POST, i.e.:The payload data that you specify will be transmitted as the POST body of your request.
Alternatively there is
WebClient.UploadValues()
to upload a name-value collection also via HTTP POST.您可以将 Upload 方法与 HTTP 1.0 POST 一起使用
You could use Upload method with HTTP 1.0 POST