今日头条竞价接口转发
生活随笔
收集整理的這篇文章主要介紹了
今日头条竞价接口转发
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、代碼
①類名
public class TouTiao{public class model{public string site_id { get; set; }public string ad_id { get; set; }public List<Data> data { get; set; }}public class Data{public string label { get; set; }public string lable { get; set; }public string value { get; set; }}}
②控制器
public class DataController : BaseController{[HttpPost]public int GetTT(){using (CR_ReservationRepository db = new CR_ReservationRepository(new Models.DBContainer())){//正規(guī)流程//1.UrlDecode://2.unicode 轉(zhuǎn)中文//var e = "{ \"site_id\": \"1598708326294535\", \"ad_id\": \"\", \"data\": [{\"lable\": \"\u623f\u5b50\u9762\u79ef\", \"id\": 1599334023368723, \"value\": \"321\", \"label\": \"\u623f\u5b50\u9762\u79ef\"}]}";var e = System.Web.HttpContext.Current.Request.Form["data"];var h = Newtonsoft.Json.JsonConvert.DeserializeObject<TouTiao.model>(e);var entity = new Models.CR_Reservation();try{entity.Flag = "今日頭條";entity.Status = 0;entity.CreateTime = Utils.ObjectToDateTime( GetValue(h.data, "時(shí)間") );entity.Tel = GetValue(h.data, "手機(jī)");entity.Name = GetValue(h.data, "稱呼");entity.Area = GetValue(h.data, "面積");entity.OpenSoure = e;}catch{entity.Flag = "錯(cuò)誤";entity.OpenSoure = e??"null";entity.Status = 0;entity.CreateTime = DateTime.Now;}db.Create(entity);return db.SaveChanges();}}private string GetValue(List<TouTiao.Data> m, string str){var s = "";try{ s = m.FirstOrDefault(x => x.label.Contains(str)).value;}catch{}return s;}}
二、過程分析
1.看官網(wǎng)文檔。curl自己本地代碼測試成功。但是不見今日數(shù)據(jù)過來,懷疑今日頭條是否轉(zhuǎn)發(fā)。
2.分析是否轉(zhuǎn)發(fā)。查看IIS站點(diǎn)日志,發(fā)現(xiàn)有數(shù)據(jù)轉(zhuǎn)發(fā)過來,準(zhǔn)備監(jiān)控流量
3.監(jiān)控訪問請求。打開WiresharkPortable,監(jiān)控iis訪問IP。查看請求過程,服務(wù)器報(bào)500錯(cuò)誤,原來表單是按鍵值對傳值。Rquest.Form["data"]獲取到數(shù)據(jù),ok
轉(zhuǎn)載于:https://www.cnblogs.com/0to9/p/9087031.html
總結(jié)
以上是生活随笔為你收集整理的今日头条竞价接口转发的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 集合、深浅拷贝、文件操作(读、写、追加)
- 下一篇: 5月学习总结(Ant-Design,mu