请求方式:POST
接口版本: v1
接口描述:
using System; using System.Text; using System.IO; using System.Net; using System.Web; namespace APIStore { class HttpRequest { /* * HTTP的Post请求方式(推荐) * strUrl 请求地址 * param 请求数据 */ public string requestPost(string strUrl, string param) { HttpWebRequest httpWebRequest = WebRequest.Create(strUrl) as HttpWebRequest; httpWebRequest.Method = "POST"; //指定允许数据发送的请求的一个协议方法 httpWebRequest.ContentType = "application/x-www-form-urlencoded"; //设置 ContentType 属性设置为适当的值 httpWebRequest.Headers.Add("appId","你的appId"); httpWebRequest.Headers.Add("appKey","你的appKey"); httpWebRequest.Headers.Add("version","5.2.3"); byte[] data = Encoding.UTF8.GetBytes(param); using (Stream stream = httpWebRequest.GetRequestStream()) { stream.Write(data, 0, data.Length); //写入数据 } WebResponse webResponse = httpWebRequest.GetResponse() as HttpWebResponse; //发起请求,得到返回对象 Stream dataStream = webResponse.GetResponseStream(); StreamReader reader = new StreamReader(dataStream, Encoding.UTF8); string returnStr = reader.ReadToEnd(); // Clean up the streams and the response. reader.Close(); webResponse.Close(); return returnStr; } /** * 获取内容 */ public void getContent() { string url="https://api-v2.1dq.com/v1/MergeImages2Pdf.json" string param="" string returnStr = null; returnStr = "post result:" + this.requestPost(url, param); Console.WriteLine(returnStr); } } }