A
A
Artem2014-12-08 21:09:55
OOP
Artem, 2014-12-08 21:09:55

c# how to get bool from webrequest?

private void SubmitData()
        {
            try
            {
                    string user = login.Text;
                    string pass = password.Text;

                    ASCIIEncoding encoding = new ASCIIEncoding();
                    string postData = "login=" + user + "&password=" + pass;
                    byte[] data = encoding.GetBytes(postData);

                    WebRequest request = WebRequest.Create("https://site.ru/auth.php");
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = data.Length;

                    Stream stream = request.GetRequestStream();
                    stream.Write(data, 0, data.Length);
                    stream.Close();
                    WebResponse response = request.GetResponse();
                    stream = response.GetResponseStream();

                    StreamReader sr = new StreamReader(stream);
                    MessageBox.Show(sr.ReadToEnd());
                    sr.Close();
                    stream.Close();
            }
                catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }

Actually, here is the code, how I need to process the request, so that when adding a conditional construct, there would be no errors about the fact that it is impossible to indirectly assign a bool value for webrequest.
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
plasticmirror, 2014-12-08
@plasticmirror

judging by the previous question "how to get authorization for a c # application from php" - is this the second part?
just read at your leisure what HTTP is and how it works
, in this case it is not necessary to wrap bool, but rather 200 OK /
401
Unauthorized at the same time, learn what using is, otherwise it hurts your eyes to look

H
haiku, 2014-12-24
@haiku

<sarcasm>Hi, I don't know how to program [in {{lang}}], please write code for me, for which I will be paid later.sarcasm>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question