Upnp:GetProtocolInfo返回400(错误请求)

弗洛里安·K。

我试图将GetProtocollInfo SOAP请求发送到Upnp MediaRenderer(在本例中为Windows Media Player)。我遵循了该教程,但是每次发送请求时,服务器都会返回400。

这是Fiddler为我提供的请求:

POST http://192.168.2.101:2869/upnphost/udhisapi.dll?control=uuid:1dc2bf33-6efe-41dd-8139-a98b9f5ca2e0+urn:upnp-org:serviceId:ConnectionManager HTTP/1.1
Accept: */ *
Content-Length: 306
Accept-Encoding: identity
Connection: Close
Host: 192.168.2.101:2869
SOAPAction: "urn:schemas-upnp-org:service:ConnectionManager:1#GetProtocolInfo"
Content-Type: text/xml; charset=utf-8
User-Agent: NativeHost
Cache-Control: no-cache


<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetProtocolInfo xmlns:u="urn:schemas-upnp-org:service:ConnectionManager:1">

</u:GetProtocolInfo>
</s:Body>
</s:Envelope>

我的生成SOAP请求的函数:

private static HttpRequestMessage MakeSoapRequest(Uri requestedUri, XElement SoapAction, String[] args)
{
    try
    {
        HttpRequestMessage m = new HttpRequestMessage(HttpMethod.Post, requestedUri);
        string attributes = "";
        if (args.Length > 0)
        {
            for (int i = 0; i <= args.Length; i = i + 2)
            {
                attributes += "<" + args[i] + ">" + args[i + 1] + "</" + args[i] + ">";
            }
        }

        string strDoc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "\r\n"+
                     "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "\r\n" +
                        "<s:Body>" + "\r\n" +
                            "<" + SoapAction.Name.LocalName + " " + "xmlns=\"" + SoapAction.Name.NamespaceName + "\">" + "\r\n" +
                            attributes + "\r\n" +
                            "</" + SoapAction.Name.LocalName + ">" + "\r\n" +
                        "</s:Body>" + "\r\n" +
                     "</s:Envelope>";
        m.Headers.Host = requestedUri.Authority;
        m.Content = new StringContent("\r\n" + strDoc, Encoding.UTF8, "text/xml");
        m.Content.Headers.ContentLength = strDoc.Length;
        m.Headers.Add("SOAPAction", "\"" + SoapAction.Name.NamespaceName + "#" + SoapAction.Name.LocalName + "\"");                
        return m;
    }
    catch (Exception e)
    {
        App.exceptionHandler(e);
        return null;
    }
}

实际发送请求的函数:

private static async Task<XDocument> GetXmlAsync(HttpClient http, HttpRequestMessage request)
{
    try
    {
        HttpResponseMessage response = await http.SendAsync(request);
        response.EnsureSuccessStatusCode();

        if (!(response.Content.Headers.ContentType.CharSet == null))
        {
            response.Content.Headers.ContentType.CharSet = response.Content.Headers.ContentType.CharSet.Trim('"');
        }

        string body = await response.Content.ReadAsStringAsync();
        return XDocument.Load(new StringReader(body));
    }
    catch (Exception e)
    {
        App.exceptionHandler(e);
        return null;
    }
}

谢谢你的帮助 :)

柯蒂斯

您是否输出了实际的消息内容?
您可能需要额外的\r\n</s:Envelope>

这是标题和内容的外观示例:

POST /ConnectionManager/ctrl HTTP/1.1
Host: 192.168.0.122:8080
Content-Length: 299
Content-Type: text/xml; charset="utf-8"
SOAPAction: "urn:schemas-upnp-org:service:ConnectionManager:1#GetProtocolInfo"

<?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:GetProtocolInfo xmlns:u="urn:schemas-upnp-org:service:ConnectionManager:1">
    </u:GetProtocolInfo>
  </s:Body>
</s:Envelope>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试获取POST以返回400错误请求

来自分类Dev

Google安全浏览返回400错误请求

来自分类Dev

Facebook Graphi API用户请求返回400错误请求

来自分类Dev

使用DotNetOpenAuth返回Amazon(400)错误请求

来自分类Dev

IIS托管的WCF服务返回HTTP 400错误请求

来自分类Dev

将JSON发布到Controller返回400错误请求

来自分类Dev

ReCaptcha在验证过程中返回400错误请求

来自分类Dev

Spring MVC @ModelAttribute方法返回“错误请求” 400

来自分类Dev

Amazon s3a使用Spark返回400错误请求

来自分类Dev

获取角色-Azure API返回(400)错误的请求

来自分类Dev

护照本地返回错误400错误请求与Angular

来自分类Dev

Azure-创建队列保留返回“(400)错误的请求”

来自分类Dev

Twethon在发布图片时返回了400(错误请求)

来自分类Dev

httr对API的POST请求返回400错误

来自分类Dev

API修补程序方法返回了错误的请求400

来自分类Dev

耗时POST请求始终返回400错误请求

来自分类Dev

axios.post返回400 React Native的错误请求

来自分类Dev

Localhost WEB Api始终返回400错误请求

来自分类Dev

Google Drive API使用PageToken返回400错误请求

来自分类Dev

卷毛不起作用并返回400错误请求

来自分类Dev

使用DotNetOpenAuth返回Amazon(400)错误请求

来自分类Dev

angularjs发布要表达4返回错误的请求400

来自分类Dev

HttpListener返回错误请求400

来自分类Dev

WCF Post方法,返回400错误请求

来自分类Dev

IdentityServer3 ResourceOwner Angular请求返回400错误请求

来自分类Dev

HttpURLConnection POST返回400错误请求

来自分类Dev

错误“远程服务器返回错误:(400)错误的请求”

来自分类Dev

错误的请求错误 400

来自分类Dev

远程服务器返回错误 (400) 错误请求

Related 相关文章

热门标签

归档