【发布时间】:2020-07-22 07:51:28
【问题描述】:
这是我的代码:
string bound = "----------------------------" +DateTime.Now.Ticks.ToString("x");
HttpRequestMessage httpreq = new HttpRequestMessage();
httpreq.Content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data; boundary=" + bound);
抛出以下异常:
对象引用未设置为对象的实例。 System.Net.Http.HttpRequestMessage.Content.get 返回 null。
我不知道为什么会这样。
谁能帮我更正我的代码?
【问题讨论】:
-
试试这个
if (httpreq.Content == null) { httpreq.Content = new StringContent(""); } -
这个怎么用?你能提供完整的代码吗?