Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Saving POST, GET, Cookies data


  • Please log in to reply
2 replies to this topic

#1 LionMdS


    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 12 April 2010 - 09:55 AM

Kind time of day!
I am writing an application which must:
1) send a POST request to a user specified address (for authorization), while retaining the request to a file.
2) obtain and maintain a file server response with the correct authorization.
3) does not send the correct POST and save to file an answer.

1) Is there a common way of authentication on most websites? if possible example.
2) How to maintain the desired me information (cookies, POST, the server response)?
3) How do I upload the site without loss of credentials obtained during authentication?
4) What methods and functions better to use to accomplish this task?

Sorry for my English! :)
Previously very grateful.
  • 0

#2 semprance


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 118 posts

Posted 12 April 2010 - 01:46 PM

Assuming you're using C# (you didn't say explicitly) and sending over HTTP, you could use HttpWebRequest and do something like this:

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.address.com/address.file");
            req.Method = "POST";
            req.Credentials = new NetworkCredential("username", "password");
            byte[] buffer = Encoding.ASCII.GetBytes("var1=blah&var2=bleh");
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = postdata.Length;

            Stream responseStream = req.GetRequestStream();
            responseStream.Write(buffer, 0, buffer.Length);

            HttpWebResponse res = req.GetResponse();

            //...Whatever you want to do with the response data

Getting Cookie data is a little more complicated, although I'm a bit vague on whether you need some/all of this information and how you're storing it etc. Either way, I hope that helps a little. For FileServer stuff, check out FtpWebRequest as well.
  • 0

#3 LionMdS


    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 13 April 2010 - 09:54 AM

Yes i using C#. Sank you for a help! But its not all information what i need. Some body can give me more information? I need to save the POST data to a txt file, and else save the response of a server to another file.
  • 0

Also tagged with one or more of these keywords: authentication

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download