Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: CS0019 Error When Trying to Concatenate Pin
tsqlmand22-Jul-09 1:57
tsqlmand22-Jul-09 1:57 
GeneralRe: CS0019 Error When Trying to Concatenate Pin
PIEBALDconsult22-Jul-09 5:21
mvePIEBALDconsult22-Jul-09 5:21 
AnswerRe: CS0019 Error When Trying to Concatenate Pin
Uri Lavi21-Jul-09 17:54
Uri Lavi21-Jul-09 17:54 
AnswerRe: CS0019 Error When Trying to Concatenate Pin
Robin_Roy21-Jul-09 18:26
Robin_Roy21-Jul-09 18:26 
QuestionClient server connection Pin
yogesh_softworld12321-Jul-09 14:31
yogesh_softworld12321-Jul-09 14:31 
AnswerRe: Client server connection Pin
yogesh_softworld12321-Jul-09 15:36
yogesh_softworld12321-Jul-09 15:36 
GeneralRe: Client server connection Pin
KornZhang21-Jul-09 19:02
KornZhang21-Jul-09 19:02 
Questionie toolbar setting cookies Pin
spelltwister21-Jul-09 12:12
spelltwister21-Jul-09 12:12 
Hello,

Here's what I'm trying to do. I need to create a toolbar that will post username/password to a webpage, get a cookie as response, and save that cookie so that the browser has access to it. Right now, I am able to send a post and save the response with the following code:
private bool getCookie()
        {
            HttpWebRequest request;
            try
            {
                string dest = "http://" + ip;
                string p = "username=un&password=pass";
                MessageBox.Show("Sending a request to: " + dest + " with creds: " + p);
                
                request = (HttpWebRequest)WebRequest.Create(dest);
                request.CookieContainer = cookieJar;

                request.Credentials = CredentialCache.DefaultCredentials;

                //Used to establish posting
                request.Method = "POST";

                Byte[] byte1 = Encoding.ASCII.GetBytes(p);

                //Set the content type of the data being posted.
                request.ContentType = "application/x-www-form-urlencoded";
                //Set the content length of the string being posted.
                request.ContentLength = byte1.Length;

                Stream newStream = request.GetRequestStream();
                newStream.Write(byte1, 0, byte1.Length);

                newStream.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                MessageBox.Show("Please ensure correct IP address.");
                return false;
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.Headers["Set-Cookie"] == null)
                return false;

            string[] cParams = response.Headers["Set-Cookie"].Split('=');
            string cName = cParams[0];
            string cValue = cParams[1];
            MessageBox.Show("Cookie name: " + cName + " Value: " + cValue);

            myCookie = new Cookie(cName, cValue);
            myCookie.Expires = DateTime.Now.AddHours(1);

            response.Cookies.Add(myCookie);
            response.Close();

            return r;
        }


However, I do not think the cookie is being saved. Also, I don't really want to have it expire in 1 hour, I would prefer it to expire at end of session, but not sure how. I want the browser to have access to the cookie for future navigation. Essentially the toolbar logs the user in and performs the first query to the system. Future queries are likely to be done thru the web interface. I tried using an HttpCookie, but I couldn't pass it to Cookies.Add() since it wants a Cookie and not HttpCookie. I tried manually adding the cookie to the header of navigate/2 by:

string h = "Cookie: name=value";
Object header = h;
navigate/2(url, null, null, null, header);

and it does add to the header, but the page does not log me in :/

Any help appreciated!

Mike

FREE 28 player online game @ http://www.1483online.com where the community drives enhancements to the game!

QuestionDeleting multiple values from the grid view and database table using windows form in C#. Pin
Omar Akhtar Sheikh21-Jul-09 11:39
Omar Akhtar Sheikh21-Jul-09 11:39 
AnswerRe: Deleting multiple values from the grid view and database table using windows form in C#. Pin
Mycroft Holmes21-Jul-09 14:57
professionalMycroft Holmes21-Jul-09 14:57 
Questionhow use the clear Pin
neha_rai21-Jul-09 10:31
neha_rai21-Jul-09 10:31 
AnswerRe: how use the clear Pin
Blue_Boy21-Jul-09 10:42
Blue_Boy21-Jul-09 10:42 
GeneralRe: how use the clear Pin
neha_rai21-Jul-09 10:49
neha_rai21-Jul-09 10:49 
GeneralRe: how use the clear Pin
0x3c021-Jul-09 11:01
0x3c021-Jul-09 11:01 
GeneralRe: how use the clear Pin
neha_rai21-Jul-09 11:49
neha_rai21-Jul-09 11:49 
GeneralRe: how use the clear Pin
Christian Graus21-Jul-09 11:01
protectorChristian Graus21-Jul-09 11:01 
GeneralRe: how use the clear Pin
neha_rai21-Jul-09 11:46
neha_rai21-Jul-09 11:46 
GeneralRe: how use the clear Pin
Christian Graus21-Jul-09 13:01
protectorChristian Graus21-Jul-09 13:01 
QuestionHow to get the selected ToolStripeItem Pin
neus8321-Jul-09 7:48
neus8321-Jul-09 7:48 
AnswerRe: How to get the selected ToolStripeItem Pin
DaveyM6921-Jul-09 9:43
professionalDaveyM6921-Jul-09 9:43 
GeneralRe: How to get the selected ToolStripeItem Pin
neus8321-Jul-09 21:45
neus8321-Jul-09 21:45 
GeneralRe: How to get the selected ToolStripeItem Pin
DaveyM6921-Jul-09 22:17
professionalDaveyM6921-Jul-09 22:17 
QuestionQ in query wizard Pin
mohammad alnoed21-Jul-09 5:59
mohammad alnoed21-Jul-09 5:59 
AnswerRe: Q in query wizard Pin
Christian Graus21-Jul-09 10:19
protectorChristian Graus21-Jul-09 10:19 
GeneralRe: Q in query wizard Pin
mohammad alnoed21-Jul-09 21:51
mohammad alnoed21-Jul-09 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.