- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 URL,我想以 data="blahblahblah"的形式发布一个带有参数的正文。但是,在这种情况下,我的“blahblahblah”是一个完整的 XML,我将其简化为如下所示:
<Parent id="1">
<Child id="1"/>
</Parent>
我可以使用以下方法使它与 HTTPClient FormUrlEncodedContent 一起正常工作。
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("data", XMLBody));
var content = new FormUrlEncodedContent(values);
HttpResponseMessage sResponse = await sClient.PostAsync(action.URL, content).ConfigureAwait(false);
现在我想让它与 StringContent 一起使用。 基本上将 xml 作为参数值的一部分发送,并且该 xml 包含“=”。下面的代码不起作用,因为我可以发布它但服务器无法识别 xml 数据。我在这里做错了什么吗?
StringContent content = new StringContent(HttpUtility.UrlEncode(action.Body), Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage sResponse = await sClient.PostAsync(action.URL, content ).ConfigureAwait(false);
最佳答案
我找到了,我必须手动输入data=部分。
StringContent content = new StringContent("data="+ HttpUtility.UrlEncode(action.Body), Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage sResponse = await sClient.PostAsync(action.URL, content ).ConfigureAwait(false);
关于c# - StringContent 与 FormUrlEncodedContent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27531419/
有人知道“mediaType”参数对 StringContent 的构造函数有什么作用吗?其 MSDN 页面上未列出任何内容。 最佳答案 哇,是啊 msdn documentation因为那个类(cl
你好, 我对编程和尝试使用 API 真的很陌生。 我从API文档中看到了这个例子 using (var content = new StringContent("{ \"orderNumber\":
我有一个 C# 桌面,需要使用 HttpClient 向我的 Node API 发出发布请求。问题是 Node 应用程序收到的 JSON 与我想要的不同。我尝试使用下面的示例,并从 StringCon
我正在使用 System.Net.Http 的 HttpClient 通过“POST”调用 REST API使用以下代码: using (HttpRequestMessage requestMessa
我有一个 URL,我想以 data="blahblahblah"的形式发布一个带有参数的正文。但是,在这种情况下,我的“blahblahblah”是一个完整的 XML,我将其简化为如下所示:
有StringContent class在 System.Net.Http 命名空间中。我应该将 StringContent 类用于什么目的? 最佳答案 StringContent 类创建适合 htt
考虑以下代码: MultipartFormDataContent MPFD = new MultipartFormDataContent(); MPFD.Add(new StringConte
我正在编写一个 API Controller ,用于接收和解析 JSON 异步帖子的内容,但无法读取该帖子中的 StringContent 对象的内容。 这是我的 API Controller 中我希
我编写了 WebApi 过滤器来检测并发问题。在 OnActionExecuted 操作中,我设置响应内容如下: actionExecutedContext.Response.Content = ne
我在访问使用 StringContent 生成的 HttpResponseMessage 中的 JSON 对象时遇到问题。 JSON 对象如下所示: { "object": "JOB",
我们有一个 Azure WebApi 服务,有时会返回这样的 BadRequest return BadRequest("{\"errors\":[{\"message\":\"MyBuddy not
我有一个看似简单的问题,但我无法在任何地方找到答案。给定以下代码: using System.Net.Http; ... StringContent sc = New Stri
我是一名优秀的程序员,十分优秀!