通过HttpClient将空主体发布到REST API [英] Post an empty body to REST API via HttpClient
问题描述
我要调用的API要求我执行POST,但正文为空.我是使用WCF Web API HttpClient的新手,我似乎找不到要写带有空正文的帖子的写代码.我找到了对某些HttpContent.CreateEmpty()方法的引用,但是由于我似乎找不到该方法,因此我认为这不是针对Web API HttpClient代码的.
The API I'm trying to call requires that I do a POST but with an empty body. I'm new to using the WCF Web API HttpClient and I can't seem to find out the write code that would do a post with an empty body. I find references to some HttpContent.CreateEmpty() method, but I don't think that is for the Web API HttpClient code since I can't seem to find that method.
推荐答案
使用从HttpContent
派生的StringContent
或ObjectContent
,也可以将null
用作HttpContent
:
Use StringContent
or ObjectContent
which derive from HttpContent
or you can use null
as HttpContent
:
var response = await client.PostAsync(requestUri, null);
这篇关于通过HttpClient将空主体发布到REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!