2017-03-07 104 views
0

我試圖與瀏覽器上的onvif相機進行通信,但目前尚未成功。以下是我用來與onvif相機進行通信的代碼。使用jquery的onvif soap消息請求

let soapMessage = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' + 
 
        '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+ 
 
        '<GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/>'+ 
 
        '</s:Body>'+ 
 
        '</s:Envelope>'; 
 

 
let ipAdd = '192.168.1.100'; 
 
let port = 80; 
 
let path = '/onvif/device_service'; 
 

 
let url = `http://${ipAdd}:${port}${path}`; 
 
$.ajax(
 
{ 
 
    type : 'POST', 
 
    url, 
 
    contentType : 'text/xml; charset="utf-8"', 
 
    dataType: "xml", 
 
    processData: false, 
 
    data \t : soapMessage, 
 
    success : processSuccess, 
 
    error \t : processError \t 
 
}); 
 

 
function processSuccess(data, status, req) 
 
{ 
 
    console.log('SUCCESS'); 
 
    } 
 

 
function processError(data, status, req) 
 
{ 
 
    console.log('ERROR'); 
 
}

我得到一個net::ERR_EMPTY_RESPONSE

我在做什麼錯。幫助需要

回答

0

我的工作示例基礎上你的問題:

var soapMessage = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' + 
 
        '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+ 
 
        '<GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/>'+ 
 
        '</s:Body>'+ 
 
        '</s:Envelope>'; 
 
        
 

 

 
var ipAdd = '192.168.2.110'; 
 
var port = 80; 
 
var path = '/onvif/device_service'; 
 

 
var wsurl = `http://${ipAdd}:${port}${path}`; 
 
jQuery.support.cors = true; 
 

 
    $.ajax({ 
 
     type: "POST", 
 
     url: wsurl, 
 
     crossDomain: true, 
 
     processData: false, 
 
     data: soapMessage, 
 
     success: processSuccess, 
 
     error: processError 
 
    }); 
 

 
}