public JObject ExecuteJson(string endpointUrl, HttpMethod method, IDictionary <string, string> headers, JObject payload) { var request = (HttpWebRequest)WebRequest.Create(WebUri.ToString() + endpointUrl); request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + AccessToken); request.Method = method.Method; request.Accept = "application/json;odata=verbose"; request.ContentType = "application/json;odata=verbose"; if (payload != null) { using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(payload); writer.Flush(); } } using (var response = (HttpWebResponse)request.GetResponse()) { using (var responseStream = response.GetResponseStream()) { using (var reader = new StreamReader(responseStream)) { var result = reader.ReadToEnd(); return(JObject.Parse(result)); } } } }
public void FilmSearchRowsHtmlDocDetailWebSiteTest() { //Arrange var html = CreateSearchRowsHtmlDocDetailWebSite(); var search = new SearchRowsDetail(); var webUri = new WebUri(HOST); //Act search.Process(html, webUri); var searchRows = search.SearchRows; var row1 = searchRows.ElementAt(0); var row2 = searchRows.ElementAt(1); //Assert Assert.Equal(2, searchRows.Count); Assert.Equal(TITLE_1, row1.Title); Assert.Equal(YEAR_1, row1.Year); Assert.Equal(DURATION_1, row1.Duration); Assert.Equal(RELEASE_1, row1.Release); Assert.Equal(HOST + LINK_1, row1.Link); Assert.Equal(TITLE_2, row2.Title); Assert.Equal(YEAR_2, row2.Year); Assert.Equal(DURATION_2, row2.Duration); Assert.Equal(RELEASE_2, row2.Release); Assert.Equal(HOST + LINK_2, row2.Link); }
public void UriCorrected() { //Act var webUri = new WebUri("https://microsoft.com"); //Assert Assert.True(webUri.AbsoluteUriCorrected); Assert.NotNull(webUri.AbsoluteUri); }
public void CalculateHost(string uri) { //Arrange //Act var webUri = new WebUri(uri); //Assert Assert.Equal("https://www.www.pl", webUri.Host); }
public void UriNotCorrected() { //Act var webUri = new WebUri("microsoft.com"); //Assert Assert.False(webUri.AbsoluteUriCorrected); Assert.Null(webUri.AbsoluteUri); }
public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return(true); } var other = obj as HostAddress; return(other != null && WebUri.IsSameHost(other.WebUri) && ApiUri.IsSameHost(other.ApiUri)); }
public void GoodRequest() { //Arrange var webUri = new WebUri("https://microsoft.com"); var request = new Request(webUri); //Act var response = request.Send(); //Asset Assert.True(response is IStatusOkResponse); }
public void BadRequest() { //Arrange var webUri = new WebUri("https://micrasfasfasfasosoftm"); var request = new Request(webUri); //Act var response = request.Send(); //Assert Assert.False(response is IStatusOkResponse); }
public void LinkSearchRowSubDetailTest() { //Arrange var link = new LinkSearchRowSubDetail(); var webUri = new WebUri(HOST); //Act link.Process(firstSearchRow, webUri); //Assert Assert.Equal(HOST + LINK_1, link.Link); }
public static async Task MWMS_Rewrite(HttpContext context) { UrlMapping u1 = new UrlMapping(); u1.Path = "2222"; Uri url = new Uri(context.Request.Scheme + "://" + context.Request.Host + context.Request.Path); WebUri u = new WebUri() { MainMobileUrl = "", }; u.AddMapping(new UrlMapping() { Path = "/acf/", PcDomain = "/pc2/", MobileDomain = "/m/" }); u.AddMapping(new UrlMapping() { Path = "/", PcDomain = "/", MobileDomain = "/m/" }); u.AddMapping(new UrlMapping() { Path = "mwms", PcDomain = "www.mwms4.com", MobileDomain = "m.mwms4.com" }); RequestUrl requestUrl = u.Build(url, context.Request.Headers["User-Agent"]); if (requestUrl.IsMobileBrowser && !requestUrl.IsMobileUrl) { //跳转至手机地址 } context.Response.WriteAsync(""); }
public override int GetHashCode() { return((WebUri?.GetHashCode() ?? 0) ^ (ApiUri?.GetHashCode() ?? 0)); }