2017-03-12 13 views
0

Upnp가 활성화 된 TV로 명령을 보내고 놀았습니다. 네트워크에서 UPNP 장치를 요청한 다음 tv를 통해 명령을 보내려면 C# 코드를 작성했습니다. 그러나 TV에 요청할 때 400 개의 잘못된 요청이 계속됩니다. 나는 Fiddler에서 봤고 이것은 RAW 요청 인 것 같다.UPnP TV에 비누 전화 요청이 잘못되었습니다.

POST http://192.168.1.4:52323/upnp/control/RenderingControl HTTP/1.1 SOAPACTION: urn:schemas-upnp-org:service:RenderingControl:1#SetVolume Content-Type: text/xml;charset="utf-8" Accept: text/xml Host: 
192.168.1.4:52323 Content-Length: 418 Expect: 100-continue Connection: Keep-Alive 

<?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> 
    <ns0:SetVolume xmlns:ns0="urn:schemas-upnp-org:service:RenderingControl:1"> 
     <InstanceId>0</InstanceId> 
     <Channel>Master</Channel> 
     <DesiredVolume>70</DesiredVolume> 
    </ns0:SetVolume> </s:Body> </s:Envelope> 

누구나이 요청에 나쁜 점이 있습니까? 여기

내가 C 번호에 WebRequest 클래스를 구성하고있어 어떻게 : 나는 전혀 코드를 제거하고 단지 피들러를 통해 요청을 형성하기 위해 노력했습니다

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); 
webRequest.Headers.Add("SOAPACTION", action); 
webRequest.ContentType = "text/xml;charset=\"utf-8\""; 
webRequest.Accept = "text/xml"; 
webRequest.Method = "POST"; 
return webRequest; 

업데이트되었습니다. 현재 라우터에 TV를 연결하지 않았으므로 라우터에 전화를 걸려고합니다. 이 피들러를 통해 내 새로 건설 된 전화입니다 :

내가 잘못된 행동 repsones, 또는 예를 들어 나쁜 XML 중 하나가 계속하지만
POST http://10.0.0.1:49153/upnp/control/Layer3Forwarding HTTP/1.1 
SOAPACTION: urn:schemas-upnp-org:service:Layer3Forwarding:1#GetDefaultConnectionService 
Content-Type: text/xml;charset="utf-8" 
Host: 10.0.0.1:49153 
Content-Length: 345 

<?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> 
    <ns0:GetDefaultConnectionService xmlns:ns0="urn:schemas-upnp-org:service:Layer3Forwarding:1"> 
    </ns0:GetDefaultConnectionService> 
    </s:Body> 
</s:Envelope> 

아래에이 응답 :

HTTP/1.1 500 Internal Server Error 
CONTENT-LENGTH: 413 
CONTENT-TYPE: text/xml; charset="utf-8" 
DATE: Tue, 14 Mar 2017 21:55:49 GMT 
EXT: 
SERVER: Linux/3.12.14, UPnP/1.0, Portable SDK for UPnP devices/1.6.18 
X-User-Agent: redsonic 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<s:Body> 
<s:Fault> 
<faultcode>s:Client</faultcode> 
<faultstring>UPnPError</faultstring> 
<detail> 
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0"> 
<errorCode>-111</errorCode> 
<errorDescription>Invalid Action</errorDescription> 
</UPnPError> 
</detail> 
</s:Fault> 
</s:Body> 
</s:Envelope> 

내 요청이 실패 할 수 방법에 대한 아이디어 ?

+1

POST 라인에서'control/Layer3Forwarding'을'Layer3Forwarding/control'으로 교체하는 것은 어떨까요? 내 장치에서 어떻게 보이는지. –

+0

조언을 주셔서 감사합니다, 내 문제는 내 SOAPACTION 따옴표가 아니라고 생각합니다. 나는 지금 바이올린으로 반응을 얻고있는 것 같습니다. Device Spy는 내 요청과 올바른 형식의 요청 간의 차이를 추적하는 데 큰 도움이되었습니다. – user1496741

답변

2

는 UPnP architecture spec 액션 호출의 형식은 귀하의 코드는 몇 가지 방법이에서 벗어나

POST path of control URL HTTP/1.1 
HOST: host of control URL:port of control URL 
CONTENT-LENGTH: bytes in body 
CONTENT-TYPE: text/xml; charset="utf-8" 
SOAPACTION: "urn:schemas-upnp-org:service:serviceType:v#actionName" 

<?xml version="1.0"?> 
< s:Envelope 
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
    <s:Body> 
    <u:actionName xmlns:u="urn:schemas-upnp-org:service:serviceType:v"> 
     <argumentName>in arg value</argumentName> 
     other in args and their values go here, if any 
    </u:actionName> 
    </s:Body> 
</s:Envelope> 

것을 말한다 : (HTTP 헤더 사이

  • 없음 줄 바꿈 (\r\n)하지 않는 한이 질문에 서식 오류가 있습니다.)
  • POST 헤더의 경로에 구성표, 호스트 또는 포트가 없어야합니다. 즉 제거 http://192.168.1.4:52323

Expect 헤더의 제거를 고려할 수도 있습니다. 추가시 이점이없는 것 같습니다 (이 헤더를 지원하는 로컬 네트워크에서 서버/프록시를 만나지는 않지만 수백 바이트의 요청 본문에 대한 오버 헤드에 대처할 수는 없습니다). 반대로,이 헤더를 처리하는 방법을 모르는 원시 HTTP 서버를 만날 수 있으므로 요청을 거부 할 수 있습니다.

+0

정보 주셔서 감사합니다! 필자는 헤더 사이에 새로운 줄이 생겼다고 생각합니다. 그것은 필기장에서 복사하는 형식 문제 일뿐입니다. 원본 게시물을 편집하여 C#에서 webRequest를 구성하는 방법을 보여줍니다. 예상 헤더를 제거하고 POST 값을 수정 해 볼 수 있습니다. – user1496741