问题描述
这是示例代码,想要在C#服务器端创建此Java脚本函数.卡住了如何传递参数"rdverb = INFO& URL ="到c#中的http侦听器.
Here is the sample code and want to create this java script function in C# server side. Stuck in how to pass parameter "rdverb=INFO&URL=" to the http listener in c#.
function Info(){
if(PortNumber === XXXX){
alert("Message.");
return;
}
var xmlHttpD = new XMLHttpRequest();
xmlHttpD.open("INFO","http://127.0.0.1:" + PortNumber +"/getInfo",true);
xmlHttpD.onload =函数(e){
如果(xmlHttpD.readyState === 4){
如果(xmlHttpD.status === 200){
alert(xmlHttpD.responseText);
}其他{
alert(xmlHttpD.statusText);
}
}
};
xmlHttpD.onerror =函数(e){
console.error(xmlHttpD.statusText);
};
var params =" rdverb = INFO& URL =''" ;;
xmlHttpD.send(params);
}
function Info() {
if(PortNumber === XXXX){
alert("Message.");
return;
}
var xmlHttpD = new XMLHttpRequest();
xmlHttpD.open("INFO", "http://127.0.0.1:" + PortNumber + "/getInfo", true);
xmlHttpD.onload = function (e) {
if (xmlHttpD.readyState === 4) {
if (xmlHttpD.status === 200) {
alert(xmlHttpD.responseText);
} else {
alert(xmlHttpD.statusText);
}
}
};
xmlHttpD.onerror = function (e) {
console.error(xmlHttpD.statusText);
};
var params = "rdverb=INFO&URL=''";
xmlHttpD.send(params);
}
推荐答案
string verb = "INFO"
string url = ""
string query = string.Format(http://127.0.0.1:{0}/getInfo?rdverb={1}&URL={2}" , PortNumber, HttpUtility.UrlEncode(url), verb);
xmlHttpD.open("INFO", query, true);
这篇关于如何在XMLHttpRequest中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!