我在制作 http POST 时遇到问题。我正在调用的 API 要求content-length
. 但我不确定如何做到这一点。
这是我的代码:
public static string publishClip(string instance_url, string sessionId, string clipId)
{
int trev = System.Text.ASCIIEncoding.Unicode.GetByteCount(instance_url + "/services/apexrest/DesktopClient/PublishClip/" + clipId);
WebRequest wrGETURL;
wrGETURL = WebRequest
.Create(instance_url
+ "/services/apexrest/DesktopClient/PublishClip/"
+ clipId);
wrGETURL.Method = "POST";
wrGETURL.ContentType = "application/json";
wrGETURL.ContentLength = trev;
wrGETURL.Headers.Add("Authorization", "Bearer " + sessionId);
Stream objStreamclipId = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStreamclipId);
return "trev";
}
谁能帮帮我?
这是我得到的错误:
{“如果设置 ContentLength>0 或 SendChunked==true,则必须提供请求正文。通过在 [Begin]GetResponse 之前调用 [Begin]GetRequestStream 来执行此操作。”}