我需要在一个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的Post,让它是一个简单的字符串值?
如果你的问题是你无法读取结果,那么可以试试这个。
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();
}