
[英]Is it possible to download an html file from a given webpage using my local network/browser as if I downloaded it myself with javascript or nodejs?
[英]Is it possible to host HTML and Javascript from server, but have it send SOAP request over my local network?
我正在尝试创建一个Web客户端来控制我的Sonos扬声器。 扬声器连接到您的wifi,并充当各种流媒体服务的媒体服务器。
它通过对UPnP操作的SOAP发布请求进行操作。 我已经弄清楚了哪些SOAP请求可以做什么,但是我无法创建一个脚本来从Web浏览器控制它。
我学校的Web服务器使用Apache,并且我尝试将以下行添加到脚本/网页所在目录的.htaccess
文件中,但无济于事:
Header set Access-Control-Allow-Origin "*"
用户是否可以通过任何方式访问该网站(即使该网站由第三方服务器托管),输入其目标设备的IP地址以及将请求从用户的IP发送到目标设备?
如果不是,可以在浏览器中本地运行此脚本,以便不涉及第三方服务器吗? 这会使它起作用吗? 如果是这样,我将如何做这些事情之一?
这是我到目前为止的代码:
<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript">
function play() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://192.168.1.197:1400/', true);
// build SOAP play request
var play =
'POST /MediaRenderer/AVTransport/Control HTTP/1.1' +
'ORIGIN: '
'HOST: 192.168.1.197:1400' +
'SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"' +
'CONTENT-TYPE: text/xml ; charset="utf-8"' +
'Content-Length: 356' +
'<?xml version="1.0" encoding="utf-8"?>' +
'<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
'<s:Body>' +
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">' +
'<InstanceID>0</InstanceID>' +
'<Speed>1</Speed>' +
'</u:Play>' +
'</s:Body>' +
'</s:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert('done. use firebug/console to see network response');
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(play);
// send request
// ...
}
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Play" onclick="play();" />
</div>
</form>
</body>
</html>
尝试运行控制台时,我从控制台收到以下错误:
XMLHttpRequest无法加载http://192.168.1.197:1400/ 。 对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http://cs12students.dce.harvard.edu ”。
我的想法是让用户输入“设备IP:端口”,或以某种方式在网络上发现它(不确定是否可行,似乎是某种安全隐患),为它分配一个变量,然后然后将其插入每个脚本以执行不同的操作。
有人已经在stackoverflow上遇到了您的问题,请链接到答案: https : //stackoverflow.com/a/24285136/6512354
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.