WebApi未显示连接;在标头中保持活动

时间:2019-01-05 15:35:48

标签: c# .net

我已经创建了要添加标头保持活动状态的webapi

我的api网址是http://api.mmwidevisions.com/get/token?booking=23&ReturnReference=0&ReturnBooking=0

      var req (HttpWebRequest)WebRequest.Create("http://api.mmwidevisions.com/");

      req.KeepAlive = true;

      req.Method = "GET";

      req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1";

        req.Accept ="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

        req.Headers.Add("Accept-Encoding:gzip,deflate,sdch");

        req.Headers.Add("Accept-Language:en-US,en;q=0.8");

        req.Headers.Add("Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3");

        req.AllowAutoRedirect = true;

        req.ContentType = "application/json";

        req.Expect = "application/json";
        var sp = req.ServicePoint;
        var prop = sp.GetType().GetProperty("HttpBehaviour",
                                BindingFlags.Instance | BindingFlags.NonPublic);
        prop.SetValue(sp, (byte)0, null);
        req.GetResponse();

0 个答案:

没有答案