Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6955091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:41:30+00:00 2026-05-27T14:41:30+00:00

I’m writing a console application program as httplistener and using it through jquery and

  • 0

I’m writing a console application program as httplistener and using it through jquery and it’s working completely true but I want to convert it to https but i don’t know the steps

Here is my code
I hope any one can solve it quickly

This is the jquery code which is written in JScript.js file

 $(function () {
    //this code is executed when the page's onload event fires
    $("#runSample1").click(function () {
        var userNameJS = $("#uName").val();
        var passwordJS = $("#passw").val();
        $.post("http://localhost:80/", { userName: userNameJS, password: passwordJS }, function (data) {
            alert(data);
        });

    });
});

this is the html page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"> </script>

    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"> </script>
    <script type="text/javascript" src="Scripts/JScript.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
    <style type="text/css">
        .style1 {
            width: 109px;
        }
    </style>
</head>
<body>
<table>

    <tr>
        <td class="style1"><label >User Name</label></td>
        <td><input id="uName"  type="text" /></td>
    </tr>
    <tr>
        <td class="style1"><label >Password</label></td>
        <td><input id="passw"  type="password" /></td>
    </tr>
    <tr>
        <td class="style1"><input id="runSample1"  type="button" value="Send" style="width: 62px"/>  </td>
    </tr>
    </table>
</body>
</html>

and the httplistener code is

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Threading;
using System.Collections.Specialized;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
namespace TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            if (!HttpListener.IsSupported)
            {
                Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
                return;
            }
            // Create a listener.
            HttpListener listener = new HttpListener();
            //listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
            listener.Prefixes.Add("http://*:8080/");
            //listener.AuthenticationSchemes
            listener.Start();
            Console.WriteLine("Listening...");
            for (; ; )
            {
                HttpListenerContext ctx = listener.GetContext();
                new Thread(new Worker(ctx).ProcessRequest).Start();
            }
        }
    }
    [DataContract]
    internal class Person
    {
        [DataMember]
        internal string name;

        [DataMember]
        internal int age;
    }
    class Worker
    {
        private HttpListenerContext context;
        public Worker(HttpListenerContext context)
        {
            this.context = context;
        }

        public void ProcessRequest()
        {

            HttpListenerRequest request = context.Request;
            List<Person> eList = new List<Person>();
            Hashtable formVars = new Hashtable(); 
            Person person;
            for (int i = 0; i <= 10;i++ )
            {
                person = new Person();
                person.name = "Pesron " + i;
                person.age = i;
                eList.Add(person);
            }
            HttpListenerResponse response = context.Response;
            System.IO.StreamReader reader = new System.IO.StreamReader(request.InputStream, request.ContentEncoding);
            // S contain parameters and values
            string s = reader.ReadToEnd();
            string[] pairs = s.Split('&');
            for (int x = 0; x < pairs.Length; x++)
            {
                string[] item = pairs[x].Split('=');
                formVars.Add(item[0],item[1]);
            }
            String userName = formVars["userName"].ToString();
            String password = formVars["password"].ToString();
            //To send any object as json to client
            DataContractJsonSerializer jsonObject = new DataContractJsonSerializer(typeof(List<Person>));
            System.IO.Stream output = response.OutputStream;
            MemoryStream ms = new MemoryStream();
            jsonObject.WriteObject(ms, eList);
            byte[] buffer = ms.ToArray();
            response.ContentType = "text/plain";
            response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
            response.ContentLength64 = buffer.Length;
            //These headers to allow all browsers to get the response
            response.Headers.Add("Access-Control-Allow-Credentials", "true");
            response.Headers.Add("Access-Control-Allow-Origin", "*");
            response.Headers.Add("Access-Control-Origin", "*");
            //This line to write to the resonse
            output.Write(buffer, 0, buffer.Length);
            output.Close();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:41:31+00:00Added an answer on May 27, 2026 at 2:41 pm

    IE is not sandboxing localhost. FF and other browsers do. They see the call to localhost as a call to the web, and this is not allowed.

    You could try to add

    Access-Control-Allow-Credentials: true
    Access-Control-Allow-Origin: *
    Access-Control-Origin: *
    

    to the headers of the HttpListener. A good paper on why this is needed can be founded here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.