C# Get answer from HTTP POST Request

Viewed 521

I am making mail.ru autoregistration. To do this, I am sending this POST-Request in C#:

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;

namespace MailCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            ///creating a client
            HttpClient webclient = new HttpClient();

            ///sending a POST request
            var response = webclient.PostAsync("https://account.mail.ru/api/v1/user/signup", new FormUrlEncodedContent(new Dictionary<string, string>{ 
                {"extented", "true"},
                { "more_password_strength", "1" },
                { "context", "signup" },
                { "from", "main" },
                { "sent_me_ads", "true" },
                { "name", Convert.ToString(new Dictionary<string, string> { { "first", "John" }, {"last", "Genry"} }) },
                { "birthday", Convert.ToString(new Dictionary<string, int> { { "day", 4 }, {"month", 5}, {"year", 1995} }) },
                { "login", "pointlesst23" },
                { "domain", "mail.ru" },
                { "password", "Tim147890" },
            }));

            ///getting a Result
            var responseString = response.Result;
            Console.WriteLine(responseString);


        }
    }
}

The problem is, that i get this answer:

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: nginx
  Date: Mon, 01 Jun 2020 11:12:11 GMT
  Transfer-Encoding: chunked
  Connection: close
  X-XSS-Protection: 1; mode=block; report=https://cspreport.mail.ru/xxssprotection
  X-Host: fau37.m.smailru.net
  X-Host: fau37.m.smailru.net
  X-Content-Type-Options: nosniff
  X-Content-Type-Options: nosniff
  X-ComScore: pageview_candidate
  Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  Strict-Transport-Security: max-age=15768000; includeSubDomains; preload
  X-Frame-Options: DENY
  Vary: Referer
  Content-Type: application/json; charset=utf-8
  Expires: Thu, 01 Jan 1970 00:00:01 GMT
}

However, I need another site answer(that i've got sending this POST-request but in python). Because in it there is a captcha ID {"body":"mOlWAphGRBZWAIv7"}Full needed answer is:

{"body":"mOlWAphGRBZWAIv7","email":null,"status":200,"htmlencoded":true}

Can someone solve this problem?)

1 Answers

use this code

 var responseString = response.Result.Content.ReadAsStringAsync().Result;

as

var responseString = response.Result;

but i suggest use await/async pattern

 var responseString =await response; 
 var bodyResponseString =await responseString.Content.ReadAsStringAsync() ;
Related