Hello,
I am trying to send PUBLICKEY
, SECRETKEY
authentication headers from my C# code to the server on WAMP, which has PHP code generated from Haxe, and I am having trouble finding out why the headers received by the server are null
.
My C# code is:
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
request.Headers.Add("PUBLICKEY", PublicKey);
request.Headers.Add("SECRETKEY", SecretKey);
request.Method = Method.ToString();
request.ContentType = ContentType;
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = "";
if (response.StatusCode != HttpStatusCode.OK)
{
var message = string.Format("Request failed. Received HTTP {0}", response.StatusCode);
MessageBox.Show(message, "Web Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
My Haxe server code is as follows:
var cnx = sys.db.Mysql.connect({
host : "localhost",
port : null,
user : "root",
pass : "",
database : "caj_news",
socket : null,
});
if (cnx == null)
{
return;
}
Manager.cnx = cnx;
var pKey = Web.getClientHeader("PUBLICKEY");
var sKey = Web.getClientHeader("SECRETKEY");
if (pKey == null)
{
Web.setReturnCode(500);
Lib.print("Public Key is null.");
return;
}
if (sKey == null)
{
Web.setReturnCode(500);
Lib.print("Secret Key is null.");
return;
}
I don’t even get any further than these null
checks, because the server is setting the return code to 500. Now, because C# is a stupid language and throws meaningless Exceptions that tell me nothing other than System.Net.WebException: 'The remote server returned an error: (500) Internal Server Error.'
, I do not know which of the above two variables are null
. My guess is both.
But why? I am clearly sending two headers with my response when calling MakeRequest
in the following C# code:
RestClient.Client.EndPoint = "http://caj-news/admin/includes/index.php?page=";
RestClient.Client.PublicKey = "2RpDDg9NGWsUvMmwuOc3yVfP6RjF0KQXRxK7ZMWIrEVKybbzglkMMRUA8tbWMhbF";
RestClient.Client.SecretKey = "oi6dQujoTkAviIfYmBxeUhErmki9Mt5ncejiFSAKhOIHYHtbOAOqlISLaagEGM0z";
var response = RestClient.Client.MakeRequest();
if (response != null)
{
MessageBox.Show("Authenticated successfully.");
}
I have checked the database and both these values match. I just don’t get it. Am I overlooking something obvious?