1iveowl / SimpleHttpListener.Rx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ajax GET always ERROR

opened this issue · comments

Hi!
I implemented SimpleHttpListener in a Xamarin forms project and used UWP for testing.
I call with JQuery / Ajax the server. Request is received, but the answer is always ERROR.
I looked into JQuery and no data is returned.
Would be great, if you could provide an example :-).
Thanks a lot!

My ajax function call:
http://localhost:9696/api/login?user=test&pass=test

function CallAjaxGet(urlStr, dataUrlEncoded, returnFunction) {
$.ajax({
url: path.concat(urlStr, "?", dataUrlEncoded),
type: "GET",
success: returnFunction,
error: function (xhr, status, error) {
document.getElementById("Error").innerHTML = "Error";
},
complete: function (event, jqXHR, options) {
document.getElementById("Hello").innerHTML = "Complete";
}
});
}

Your example code:

    static async Task SendResponseAsync(IHttpRequestResponse request, HttpSender httpSender)
    {
        if (request.RequestType == RequestType.TCP)
        {
            var response = new HttpResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                ResponseReason = HttpStatusCode.OK.ToString(),
                Headers = new Dictionary<string, string>
        {
            {"Date", DateTime.UtcNow.ToString("r")},
            {"Content-Type", "text/html; charset=UTF-8" },
        },
                Body = new MemoryStream(Encoding.UTF8.GetBytes($"<html>\r\n<body>\r\n<h1>Hello, World! {DateTime.Now}</h1>\r\n</body>\r\n</html>"))
            };

            await httpSender.SendTcpResponseAsync(request, response).ConfigureAwait(false);
        }
    }

I'm sorry but I can't really detemine what's going on from the above.