/// <summary> /// Initializes the library with extended parameters. /// </summary> /// <param name="appId">Unique VK app identifier. Get it at vk.com/dev -> App Settings</param> /// <param name="appSecret">App secret key. Used only with secure section methods and with direct auth.</param> /// <param name="apiVersion">API version the library is going to use. Min: 5.63</param> /// <param name="requestMethod">GET or POST requests the library should use?</param> /// <param name="parseJson">Should the library log received JSONs or focus on performance?</param> /// <param name="logger">Logger the library should use. By default is logs info into DEBUG output.</param> public Vkontakte(int appId, ILogger logger, string appSecret = "", string apiVersion = "5.63", RequestMethod requestMethod = RequestMethod.Get, ParseJson parseJson = ParseJson.FromString) { AppId = appId; Logger = logger; AppSecret = appSecret; ApiVersion = apiVersion; HttpService = new DefaultHttpService(logger); _requestMethod = requestMethod; _parseJson = parseJson; }
public void QueryBuilder() { const string baseUrl = "http://a.bcd/ef.gh"; var parameters = new Dictionary <string, string> { { "foo", "bar" }, { "key", "1234" } }; using (var defaultHttpService = new DefaultHttpService(Logger)) defaultHttpService .BuildGetRequestUrl(baseUrl, parameters) .Should().Be("http://a.bcd/ef.gh?foo=bar&key=1234"); }
public async void HttpBinPostSingle() { var url = new Uri("http://httpbin.org/post"); using (var defaultHttpService = new DefaultHttpService(Logger)) using (var stream = await defaultHttpService.PostSingleFileAsync(url, new byte[] { 1 }, "doc", "doc")) using (var streamReader = new StreamReader(stream)) using (var jsonTextReader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); var response = serializer.Deserialize <JToken>(jsonTextReader); var content = response["files"]["doc"].ToString(); content.Should().Be(@""); } }
public async void HttpBinPostMultiple() { var url = new Uri("http://httpbin.org/post"); var parameters = new Dictionary <string, byte[]> { { "one", new byte[] { 1 } }, { "two", new byte[] { 1 } } }; using (var defaultHttpService = new DefaultHttpService(Logger)) using (var stream = await defaultHttpService.PostMultipleFilesAsync(url, parameters)) using (var streamReader = new StreamReader(stream)) using (var jsonTextReader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); var response = serializer.Deserialize <JToken>(jsonTextReader); response.Should().NotBeNull(); } }
public async void HttpBinGetForStream() { var url = new Uri("http://httpbin.org/get"); var parameters = new Dictionary <string, string> { { "foo", "bar" } }; using (var defaultHttpService = new DefaultHttpService(Logger)) using (var stream = await defaultHttpService.GetForStreamAsync(url, parameters)) using (var streamReader = new StreamReader(stream)) using (var jsonTextReader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); var response = serializer.Deserialize <JToken>(jsonTextReader); response["args"]["foo"].ToString().Should().Be("bar"); response["url"].ToString().Should().Contain(url.AbsoluteUri); } }
public async void VkApiPostForStream() { var url = new Uri("https://api.vk.com/method/users.get"); var parameters = new Dictionary <string, string> { { "user_ids", "1" } }; using (var defaultHttpService = new DefaultHttpService(Logger)) using (var stream = await defaultHttpService.PostForStreamAsync(url, parameters)) using (var streamReader = new StreamReader(stream)) using (var jsonTextReader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); var response = serializer.Deserialize <JToken>(jsonTextReader); var content = response["response"][0]; content["first_name"].ToString().Should().Be("Павел"); content["last_name"].ToString().Should().Be("Дуров"); } }
public virtual bool CheckServer(out HttpResult res) { try { var x = new DefaultHttpService(Paths.ConfigUrl); var result = x.Get(""); res = new HttpResult(result.StatusCode); return(result.StatusCode == HttpStatusCode.OK); } catch (CodeShellHttpException ex) { res = new HttpResult(ex.Status, ex.Message); res.SetException(ex); return(false); } catch (Exception exx) { res = new HttpResult(HttpStatusCode.NotFound, exx.Message); res.SetException(exx); return(false); } }