接下來(lái)就開(kāi)始寫第一個(gè)接口,最簡(jiǎn)單的直接接收字符串
[HttpPost, Route("get/context")] public int getContext(context_ context) { bool result = false; //短信數(shù)據(jù) returnForm context_data = XmlSerializeUtil.Deserialize(typeof(returnForm), context.context) as returnForm; if (context_data != null && context_data.count > 0) { result = UpdateDB(context_data); } return result ? 100 : 500; }
這里我定義了一個(gè)類context_,調(diào)用之前寫的方法反序列化實(shí)體類,再寫入數(shù)據(jù)庫(kù)
第二個(gè)接口時(shí)接收請(qǐng)求中的xml(text/xml)
[HttpPost, Route("get/context")] public int getContext(context_ context) { bool result = false; //短信數(shù)據(jù) returnForm context_data = XmlSerializeUtil.Deserialize(typeof(returnForm), HttpContext.Current.Request.InputStream) as returnForm; if (context_data != null && context_data.count > 0) { result = UpdateDB(context_data); } return result ? 100 : 500; }
這里讀取了請(qǐng)求中的內(nèi)容,HttpContext.Current.Request.InputStream
第三種是讀取文件
[HttpPost, Route("get/context")] public int getContext(context_ context) { bool result = false; HttpFileCollection files = HttpContext.Current.Request.Files; foreach (string key in files.AllKeys) { HttpPostedFile file1 = files[key]; file1.InputStream.ToString(); returnForm context_data = XmlSerializeUtil.Deserialize(typeof(returnForm), file1.InputStream) as returnForm; if (context_data != null && context_data.count > 0) { result = UpdateDB(context_data); } } return result ? 100 : 500; }
遍歷文件內(nèi)容,獲取數(shù)據(jù)
總結(jié)
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com