Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody! I want to write a program in C# that will automatically create email accounts and for this purpose I wrote a captcha reader class. Now I want to create a POST command that will send to the server the data about user. How can I correctly determine the format of the command?
HEre is what i wrote:
//-------------------------------------------------------------------------------
//Create HttpWebRequest instance
            HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(url);
//specify the method
            postRequest.Method = "Post";
            postRequest.ContentType = "application/x-www-form-urlencoded";
//create namevalue collection for sending to the server name value pairs (is it //correctly?)
            NameValueCollection nvc = new NameValueCollection();
            nvc.Add("_token", sessionID);
            nvc.Add("_uname", "lalala123");
            .........
//I dont know how should I exactly create the message
            byte[] btPostData = Encoding.ASCII.GetBytes("_token" + nvc.Get("_token"));

            postRequest.ContentLength = btPostData.Length;
            Stream postData = postRequest.GetRequestStream();
            postData.Write(btPostData, 0, btPostData.Length);
            HttpWebResponse response2 = (HttpWebResponse)postRequest.GetResponse();
            Stream responseStream2 = response.GetResponseStream();
            StreamReader reader2 = new StreamReader(responseStream2);
            String response22 = reader2.ReadToEnd();
            ;
//-------------------------------------------------------------------------------

Thanks in advance!

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 16-Apr-11 8:37am
v2
Comments
Patrick Kalkman 17-Apr-11 8:26am    
Can you tell me what is wrong with your implementation, does it give an error? If so, what kind of error?
EricThe 27-Dec-11 22:39pm    
i sure would like to see the captcha reader code cause i am trying to do one need some ideas

1 solution

Hi,

I don't know what parameters you want (need) to send but how create post params in general you can find here[^]. There are many other examples on net.

In general post data is formatted like any other query string (Key1=Value1&Key2=Value2 and so on...)
Yours post data will look like this: _token=100&_uname=lalala123
Also when you creating post data you need to encode values using
C#
System.Web.HttpUtility.UrlEncode()
method.
And that's pretty much all you need to make successful post request...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900