Jump to content

Saving POST, GET, Cookies data

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
LionMdS

LionMdS

    Newbie

  • Members
  • Pip
  • 3 posts
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.

Questions:
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.

#2
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
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);
            responseStream.Close();

            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.

#3
LionMdS

LionMdS

    Newbie

  • Members
  • Pip
  • 3 posts
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.