我需要在Post中将字符串值作为文本传递。
我尝试了以下
string content = "91237932,xy91856,0,0";
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["AttributesApi"] + $"/api/UserProfiles/UpdateUserProfileFromIAM", new StringContent(content));
这是我必须使用的(不能更改它的存在),但是该值为空
[HttpPost("UpdateUserProfileFromIAM")]
public async Task<ActionResult> UpdateUserProfileFromIAM(string attributes)
{
//attributes null
}
如何处理此HttpClient帖子,使其成为简单的字符串值?
答案 0 :(得分:0)
如果您的问题是无法阅读结果,请尝试以下操作:
public async Task<string> GetData()
{
string content = "91237932,xy91856,0,0";
using var client = new HttpClient();
var response = await client.PostAsync(ConfigurationManager.AppSettings["AttributesApi"] + $"/api/UserProfiles/UpdateUserProfileFromIAM", new StringContent(content));
return await response.Content.ReadAsStringAsync();
}