Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-02-2009
Member
 
Join Date: Jan 2009
Posts: 36
Method to post postdata & get the result

Hello,
Working on dotnet platform.
I want to know how can I use the objects provided in System.net to download the page using the post method? WebClient can send a querystring to a page but dont know how to use the POst method for getting it. Tried with the WebClient.UploadData() & i9t can download a page but cant send the postdata.
Anyone knows where I am wrong? help please!
Reply With Quote
  #2  
Old 02-02-2009
Member
 
Join Date: May 2008
Posts: 72
Re: Method to post postdata & get the result

According to me you need to use the "|" character to delimiter the fields for POST...

Dim PostData As Byte() = ASCIIEncoding.GetBytes("Account=" & Account &
"Password=" & Password)


should be:

Dim PostData As Byte() = ASCIIEncoding.GetBytes("Account=" & Account &
"|Password=" & Password & "|")


Hope this helps
Reply With Quote
  #3  
Old 02-02-2009
Member
 
Join Date: Jan 2009
Posts: 44
Re: Method to post postdata & get the result

For post data to PHP in C# I use this method:

Quote:

public string Post(string url, string data) {


string vystup = null;
try
{
//Our postvars
byte[] buffer = Encoding.ASCII.GetBytes(data);
//Initialisation, we use localhost, change if appliable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";
//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;
//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
//Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
vystup = _Answer.ReadToEnd();

//Congratulations, you just requested your first POST page, you
//can now start logging into most login forms, with your application
//Or other examples.
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return vystup.Trim()+"\n";

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Method to post postdata & get the result"
Thread Thread Starter Forum Replies Last Post
The Search Result in Outlook 2007 does not show current years result Shika Windows Software 4 24-04-2012 07:53 AM
want to send hidden chronicles post to neighbors but instead post is going to general feed. Shiraj Video Games 1 26-01-2012 12:27 AM
How many post are allowed to post on a blog in a single day umaymah Technology & Internet 3 16-01-2011 06:11 AM
How to remove postdata confirmation dialog KALINDA Technology & Internet 3 02-11-2009 11:16 PM
What is Post and Get Method in PHP? How it has been implemented? Rover Software Development 3 05-09-2009 08:23 AM


All times are GMT +5.5. The time now is 03:32 AM.