(click button1).
It success, however, after that, I click button2 and
want to get data thru button 2, but it still return me 401 but I have authenticate thru button 1 already.
how to store the authenticate to C# .net (windows form application)?
below is info from the rest api manual,
Client sends a valid Basic Authentication header to the authentication point. BTW I can get the LWSSO_COOKIE_KEY but how to use it for another web request to access other data
GET /qcbin/authentication-point/authenticate
Authorization: Basic ABCDE123
Server validates the Basic authentication headers, creates a new LW-SSO token and returns it as LWSSO_COOKIE_KEY.
HTTP/1.1 200 OK
Set-Cookie: LWSSO_COOKIE_KEY={cookie}
he application can now access data and services using the token. At the end of the session, log off to discard the token.
Expand|Select|Wrap|Line Numbers
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- Uri uri = new Uri("http://localhost:8080/qcbin/authentication-point/authenticate");
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
- request.Method = "POST";
- NetworkCredential credentials = new NetworkCredential("user", "password");
- request.Credentials = credentials;
- WebResponse v = request.GetResponse();
- Stream rStream = v.GetResponseStream();
- StreamReader str = new StreamReader(rStream);
- if (str.EndOfStream != true)
- {
- richTextBox1.Text = str.ReadToEnd();
- }
- v.Close();
- rStream.Close();
- str.Close();
- richTextBox1.Text = "success";
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
- }
- }
Expand|Select|Wrap|Line Numbers
- private void button2_Click_1(object sender, EventArgs e)
- {
- HttpWebRequest request
- = WebRequest.Create("http://localhost:8080/qcbin/rest/domains/DEFAULT/projects/demoproject/defects") as HttpWebRequest;
- // Get response
- using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
- {
- // Get the response stream
- StreamReader reader = new StreamReader(response.GetResponseStream());
- // output
- richTextBox1.Text = reader.ReadToEnd();
- }
- }