找不到如何使用 HttpContent [英] Can't find how to use HttpContent

查看:14
本文介绍了找不到如何使用 HttpContent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 HttpContent:

HttpContent myContent = HttpContent.Create(SOME_JSON);

...但是我没有找到定义它的 DLL 的运气.

...but I am not having any luck finding the DLL where it is defined.

首先,我尝试添加对 Microsoft.HttpSystem.Net 的引用,但都没有在列表中.我还尝试添加对 System.Net.Http 的引用,但 HttpContent 类不可用.

First, I tried adding references to Microsoft.Http as well as System.Net, but neither is in the list. I also tried adding a reference to System.Net.Http but the HttpContent class is not available.

那么,谁能告诉我在哪里可以找到 HttpContent 类?

So, can anyone tell me where I can find the HttpContent class?

推荐答案

只需使用...

var stringContent = new StringContent(jObject.ToString());
var response = await httpClient.PostAsync("http://www.sample.com/write", stringContent);

或者,

var stringContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync("http://www.sample.com/write", stringContent);

这篇关于找不到如何使用 HttpContent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆