I have a class with some methods for web requests, for example:
public class BiPRORequests
{
private readonly string HOST;
public BiPRORequests()
{
HOST = "server";
}
public RemoteCertificateValidationCallback ServerCertificateValidationCallback { get; set; }
public string authenticate(string un, string pw)
{
try
{
HttpWebRequest request = HttpWebRequest.CreateHttp(string.Format("https://{0}/bipro/authenticate", HOST));
request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
request.Method = "POST";
request.ContentType = "text/xml";
string postData = @"some connection string" + un + pw;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string bipro;
if (response.StatusCode == HttpStatusCode.OK)
{
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
string te = Convert.ToString(response.StatusCode);;
bipro = responseFromServer.Substring(821, 36);
reader.Close();
dataStream.Close();
response.Close();
return bipro;
}
return "error: ";
}
catch (WebException ex)
{
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
string te = reader.ReadToEnd();
}
string exe = Convert.ToString(ex.Message);
return exe;
} }
And I have a program in another file that looks like this at the moment:
static void Main(string[] args)
{
BiPRORequests testcon = new BiPRORequests();
string test = testcon.authenticate("username", "password"));
}
My question is, there are several variables that get declared in the authenticate method and I want to get the 'generated' values of those variables. I would need postData, responseFromServer and bipro, but the method can only return one value (bipro). Is there any other way to access the values in my main method?
(I am trying to get them so I can compare them to the correct values to see if there are any errors within the method. I know there are several similar questions on this site, but I haven't found one that could help me.)