I wrote an HttpHandler in C# to do some salting and hashing and send an id back to my webpage. The webpage sends the user's first and last name to the handler, which salts and hashes it, and sends the hash back to the webpage.
function redirectToCustom(){
var firstName = "First";
var lastName = "Last";
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
var surveyURL = "https://www.google.com";
var uri = surveyURL + "?id=" + encodeURIComponent(xmlHttp.responseText);
window.location = uri;
}
};
xmlHttp.open("GET", "http://myhandler/GetHash.ashx?fname=" + encodeURIComponent(firstName) + "&lname=" + encodeURIComponent(lastName), true);
xmlHttp.send(null);
}
The code for the handler, GetHash.ashx is below,
string fName = context.Request.QueryString["fname"];
string lName = context.Request.QueryString["lname"];
string fullName = string.Concat(fName, lName);
string saltAndHash = PasswordHash.CreateHash(fullName);
SaveToTable(saltAndHash);
context.Response.ContentType = "text/plain";
context.Response.Write(saltAndHash.Split(':')[2]);
The problem is when I debug the webpage, there is no response text.
I looked in Fiddler, and there is a response body, but it is encoded, and I can't figure out why the body is encoded, and how it is encoded.
Why is my response body coming through encoded?
The answer was very simple, and was pointed out to me in the comments. The response is is gzipped.
I missed this in the headers
Content-Encoding: gzip
Now I have to figure out how to decompress response text using native JavaScript.