-1

I tried to use this code below(copied from somewhere) to POST my name to the website and start chatting but I receive 404 error; i guess i'm writing the wrong url or the string to be posted.

static void Main(string[] args)
        {
            string response = HttpPostRequest("https://tlk.io/tactic5", "name=Ali");
            Console.WriteLine(response);
            Console.ReadLine();
        }
        public static string HttpPostRequest(string url, string post)
        {
            var encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(post);
            WebRequest request = WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            Stream stream = request.GetRequestStream();
            stream.Write(data, 0, data.Length);
            stream.Close();
            WebResponse response = request.GetResponse();
            String result;
            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                result = sr.ReadToEnd();
                sr.Close();
            }
            return result;
        }

I guess the most important part of the html I should use is this:

<input id="participant_nickname" class="input-text join-input--
troll" name="participant[nickname]" placeholder="Name" size="30" 
spellcheck="false" type="text">

I'm not a skilled programmer.

Mh12x
  • 1

1 Answers1

0

I think y should check this post: How to use verb GET with WebClient request?

Why you sending POST request exactly? Are someone told you to use POST?

EDIT 1: Read about Selenium WebDriver C#

hamaronooo
  • 471
  • 4
  • 20
  • I think in this case u litteraly can not fill input elemnt in web site form by using POST requests... They (POST requests) not intended for this purpose. – hamaronooo Jun 25 '21 at 09:12
  • I visited this link https://forums.asp.net/t/1572303.aspx?Programatically+specify+values+and+submit+a+form+remotely+ so i started with POST. – Mh12x Jun 25 '21 at 10:20
  • if u want to do some actions at website from c#, you need to google about XPATH and maybe about some authomatic tests. !!! Read About: Selenium WebDriver - thats what you need i think – hamaronooo Jun 25 '21 at 10:22
  • from the link you offered, I got that the "GET request" doesn't send anything to server! but I want to submit my name. – Mh12x Jun 25 '21 at 10:36
  • oh I forgot to thank you for helping me. thank you. – Mh12x Jun 25 '21 at 10:38
  • if you know what EXACTLY do submit button at your website (u can check it at F12 tab in browser), i can help you. Now I think you dont have this information ;) – hamaronooo Jun 25 '21 at 10:43
  • I'm glad I'm not alone in this(this is about my first C# question). ok now I used F12 and as you see in this picture below: https://s4.uupload.ir/files/2021_06_25_15_31_06_896x544_m9du.bmp the name of the element I want to send is "Name" ; I tried POSTing "Name=itsme" but still got 404 error. there's no submit button(I shoud just press ENTER). – Mh12x Jun 25 '21 at 11:11