Ejemplo n.º 1
0
        private async Task <TokenResponse> GetTokenAsync()
        {
            var now      = DateTime.Now.Second;
            var response = await _httpClient.GetAsync($"{Endpoints.GetToken}{now}").As <dynamic>();

            var csrfToken = (string)response.token;

            response = await _httpClient.GetAsync(Endpoints.ValidateToken)
                       .WithHeader("Cookie", $"csrf_token={csrfToken}")
                       .As <dynamic>();

            var multiPart = new MultipartFormDataContent();

            multiPart.Add(new StringContent(csrfToken), ":cq_csrf_token");
            multiPart.Add(new StringContent(_username), "username");
            multiPart.Add(new StringContent(_password), "password");
            multiPart.Add(new StringContent("https://owners.hyundaiusa.com/us/en/index.html"), "url");

            var strResponse = await _httpClient.PostAsync(Endpoints.Auth)
                                                               //.WithHeader("Cookie", $"csrf_token={csrfToken}")
                              .WithBody(multiPart).AsString(); //.As<string>();

            var responseJson = JsonConvert.DeserializeObject <dynamic>(strResponse);
            var tokenJObj    = (JObject)responseJson.Token;

            return(tokenJObj.ToObject <TokenResponse>());
        }
Ejemplo n.º 2
0
 public static async Task <JObject> PostRequest_NoBody(FluentClient client, string uri, CancellationToken cancellationToken)
 {
     return(await client
            .PostAsync(uri)
            .WithCancellationToken(cancellationToken)
            .AsRawJsonObject());
 }
Ejemplo n.º 3
0
 internal static async Task <IDictionary <string, ModInfoModel> > CheckModUpdate(string[] modKeys, MainWindow mf)
 {
     using (IClient client = new FluentClient("https://api.smapi.io/v2.0/"))
     {
         return(await client
                .PostAsync("mods", new ModSearchModel(modKeys))
                .As <IDictionary <string, ModInfoModel> >());
     }
 }
Ejemplo n.º 4
0
        public static async Task <JObject> PostRequestAsync(String uri, String parameters)
        {
            {
                //using (var httpClient = new HttpClient())
                //{
                //    using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.bitbucket.org/2.0/repositories/WildWoz/test-repo/src"))
                //    {
                //        var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("WildWoz:F4vTWxGmZTgQDkTYgk6m"));
                //        request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");

                //        var multipartContent = new MultipartFormDataContent();
                //        multipartContent.Add(new ByteArrayContent(File.ReadAllBytes("C:/Users/adam.wozniak/Desktop/NewFolder/test.txt")), "/test15.txt", Path.GetFileName("C:/Users/adam.wozniak/Desktop/NewFolder/test.txt"));
                //        request.Content = multipartContent;

                //        var response = await httpClient.SendAsync(request);
                //    }
                //}


                var username = "******";
                var password = "******";
                var plainText_usernamePassword     = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
                var base64encoded_usernamePassword = System.Convert.ToBase64String(plainText_usernamePassword);


                var defaultHttpClient = new HttpClient();
                defaultHttpClient.DefaultRequestHeaders
                .Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64encoded_usernamePassword);

                IClient client   = new FluentClient("https://api.bitbucket.org/2.0/", defaultHttpClient);
                var     messages = new JObject();

                var multipartContent = new MultipartFormDataContent();
                multipartContent.Add(new ByteArrayContent(File.ReadAllBytes("C:/Users/adam.wozniak/Desktop/NewFolder/TestDoc.docx")), "/a-tashFile-docx.docx", Path.GetFileName("C:/Users/adam.wozniak/Desktop/NewFolder/TestDoc.docx"));
                multipartContent.Add(new StringContent("comitting Tash first docx file."), "message");

                var url         = "repositories/WildWoz/test-repo2/src";
                var responseRaw = await client
                                  .PostAsync(url)
                                  .WithBody(multipartContent)
                                  .AsString();

                var response = new JObject();
                if (responseRaw == "")
                {
                    response = JObject.Parse("{\"response\":\"Commit successful\"}");
                }
                else
                {
                    response = JObject.Parse(responseRaw);
                }
                Console.WriteLine(responseRaw);

                return(response);
            }
        }
Ejemplo n.º 5
0
            public static async Task <Responses.RemovePlayerGameBanResponse> RemovePlayerGameBan(ulong steamId)
            {
                var responseData = await FluentClient.PostAsync("ICheatReportingService/RequestPlayerGameBan/v1")
                                   .WithArgument("key", PublisherApiKey)
                                   .WithArgument("appid", AppId)
                                   .WithArgument("steamid", steamId)
                                   .As <SteamworksWebApiResponse2 <Responses.RemovePlayerGameBanResponse> >();

                return(responseData.Response);
            }
Ejemplo n.º 6
0
        public async Task <IEnumerable <ModEntryModel> > PostAsync([FromBody] ModSearchModel model)
        {
            using IClient client = new FluentClient("https://smapi.io/api");

            Startup.ConfigureJsonNet(client.Formatters.JsonFormatter.SerializerSettings);

            return(await client
                   .PostAsync(this.Request.Path)
                   .WithBody(model)
                   .AsArray <ModEntryModel>());
        }
Ejemplo n.º 7
0
            public static async Task <Responses.RequestPlayerGameBanResponse> RequestPlayerGameBan(ulong steamId, ulong reportId, string description, uint duration, bool delayBan = false, uint flags = 0)
            {
                var responseData = await FluentClient.PostAsync("ICheatReportingService/RequestPlayerGameBan/v1")
                                   .WithArgument("key", PublisherApiKey)
                                   .WithArgument("appid", AppId)
                                   .WithArgument("steamid", steamId)
                                   .WithArgument("reportid", reportId)
                                   .WithArgument("cheatdescription", description)
                                   .WithArgument("duration", duration)
                                   .WithArgument("delayban", delayBan)
                                   .WithArgument("flags", flags)
                                   .As <SteamworksWebApiResponse2 <Responses.RequestPlayerGameBanResponse> >();

                return(responseData.Response);
            }
Ejemplo n.º 8
0
        public static async Task <JObject> PostRequest_WithBody(FluentClient client, string uri, CancellationToken cancellationToken, MultipartFormDataContent multipartContent)
        {
            var responseRaw = await client
                              .PostAsync(uri)
                              .WithCancellationToken(cancellationToken)
                              .WithBody(multipartContent)
                              .AsString();

            var response = new JObject();

            if (responseRaw == "")
            {
                response = JObject.Parse("{\"response\":\"Commit successful\"}");
            }
            else
            {
                response = JObject.Parse(responseRaw);
            }
            return(response);
        }
Ejemplo n.º 9
0
        public async Task Request_CanResubmit_Post([Values("string", "stream")] string contentType)
        {
            // arrange
            int counter  = 0;
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Post, "https://api.fictitious-vendor.com/v1/endpoint").Respond(HttpStatusCode.OK, testRequest => new StringContent($"This is request #{++counter}"));

            var httpClient   = new HttpClient(mockHttp);
            var fluentClient = new FluentClient("https://api.fictitious-vendor.com/v1/", httpClient);

            // act
            var request = fluentClient.PostAsync("endpoint");

            switch (contentType)
            {
            case "string":
                request = request.WithBodyContent(new StringContent("example string"));
                break;

            case "stream":
                Stream stream = new MemoryStream(Encoding.UTF8.GetBytes("Example stream content"));
                request = request.WithBodyContent(new StreamContent(stream));
                break;

            default:
                throw new NotSupportedException("Unknown content type.");
            }

            string valueA = await request.AsString();

            string valueB = await request.AsString();

            // assert
            Assert.AreEqual("This is request #1", valueA, "The first request got an unexpected value.");
            Assert.AreEqual("This is request #2", valueB, "The second request got an unexpected value.");
        }
Ejemplo n.º 10
0
        public IRequest PostAsync(string resource)
        {
            var request = _client.PostAsync(resource);

            return(SetRequestDefaults(request));
        }