2
내가 http-listener에 같은 콘솔 응용 프로그램을 작성하고 JQuery와 통해 사용하고 완전히 사실 일하고하지만 HTTPS로 변환하고 싶지만 내가 단계 여기는 HTTP Listener에 문제
을 모르는거야 내 코드 입니다 나는 어떤 사람이이 JScript.js에 기록 된 jQuery 코드는이 HTML 페이지
,369입니다$(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);
});
});
});
파일입니다
신속하게 해결할 수 있기를 바랍니다
<!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>
1,363,210 및 http-listener에 코드는 IE가 로컬 호스트를 샌드 박스되지
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();
}
}
}
죄송합니다. httplistener 클래스가 이미 모든 브라우저에서 요청을 받았지만 인터넷 탐색기에서 가져 오는 응답 문자열을 다시 보내고 다른 브라우저에서는 응답하지 않는다고 말하고 싶습니다. – fighter
피들러는 무엇을합니까? 너를 줘? – mslot
나는 개발자 도구를 사용하고 있으며 $ .post ("http : // localhost : 80 /", {userName : userNameJS, password : passwordJS}, function (data) { alert (data) ; }}); 그것은 데이터를 보여 주지만 mozilla에서 방화 켓을 사용할 때 에러를 보여줍니다 – fighter