내 네트워크에 iotdevice.local이라는 광고를 보내는 장치가 있는데,이 도메인에 http 요청을 보낼 수 있습니다. Bonjour 설치 후 Windows PC. 하지만 나는이 장치와 자주 통신 할 이온 응용 프로그램을 개발 중입니다. 그래서 나는 cordova-zeroconf-plugin을 사용하고 있습니다. (https://www.npmjs.com/package/cordova-plugin-zeroconf). .local 서비스 감시를 추가 할 때 서비스가 표시됩니다. 하지만 내 요청은 $ http 함수에서 iotdevice.local을 사용할 때 실패합니다. 내가 가진이 코드 App.jsandroid, corova-zeroconf-plugin을 사용하여 .local 도메인의 장치와 통신 할 수 없습니다.
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
console.log("device ready");
var zeroconf = cordova.plugins.zeroconf;
zeroconf.watch('_http._tcp.local.', function(result) {
var action = result.action;
var service = result.service;
console.log(JSON.stringify(result));
if (action == 'added') {
console.log('service added', service);
} else {
console.log('service removed', service);
}
});
}
그것은 잘 작동하고 로그에 내가 내 장치
012 3,516,{ "행동"을 참조하십시오 : "서비스"를 "추가": { "응용 프로그램을 ":"http ","domain ":"local ","port ": 80,"name ":"iotdevice ","server ":"iotdevice.local. ","description ":"\ 00 ","protocol ","tcp ","qualifiedname ":"iotdevice._http._tcp.local. ","type ":"_ http._tcp.local. ","txtRecord ": {},"addresses ": ["192.168.0.4 "],"urls ": ["http://192.168.0.4:80 "]}}
하지만 controller.js이를 사용하는 경우 -
$scope.sendRequest2 = function(){
$http({
method: 'GET',
url: 'http://iotdevice.local/events?id=600194067eba&action=socket1off'
}).then(function successCallback(response) {
$scope.req2succes=true;
console.log("Sent");
}, function errorCallback(response) {
console.log(JSON.stringify(response));
console.log("Could not Sent");
$scope.req2succes=false;
});
}
그것은 작동하지 않습니다. 요청 상태는 항상 -1입니다. 누구든지 나를 어떻게 도와 드릴 수 있습니까? 근본적으로 잘못된 것을하고 있습니까?
if (action == 'added')를 if (action == 'resolved')로 바꾸어보십시오. 그것은 나를 위해 일했다. – alfredo