将正文添加到与azure服务mgmt api一起使用的HttpWebRequest
我将如何添加到HttpWebRequest的主体?
身体需要由以下组成
base-64-encoded-configuration-file true|false Auto|Manual
任何帮助深表感谢
byte[] buf = Encoding.UTF8.GetBytes(xml); request.Method = "POST"; request.ContentType = "text/xml"; request.ContentLength = buf.Length; request.GetRequestStream().Write(buf, 0, buf.Length); var HttpWebResponse = (HttpWebResponse)request.GetResponse();
不了解Azure,但这里只是使用HttpWebRequest
发送数据的一般大纲:
string xml = " "; var payload = UTF8Encoding.UTF8.GetBytes(xml); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://foo.com"); request.Method = "POST"; request.ContentLength = payload.Length; using(var stream = request.GetRequestStream()) stream.Write(payload, 0, payload.Length);
如果由于某种原因不需要 HttpWebRequest
,使用WebClient
上传数据要简洁得多:
using (WebClient wc = new WebClient()) { var result = wc.UploadData("https://foo.com", payload); }
可以免费下载我的书章,其中展示了如何使用Windows Azure Service Management API(以及创建有效负载)。
上述就是C#学习教程:将正文添加到与azure服务mgmt api一起使用的HttpWebRequest分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1009469.html