通知中心Rest API -指定的资源描述无效

本文关键字:资源 描述 无效 -指 Rest API 通知 | 更新日期: 2023-09-27 18:13:45

好的,所以当我试图做一个创建注册调用到其余api我得到错误"指定的资源描述无效"。

我假设xml体有问题,但当测试邮差它的工作,所以我可能做错了loadXml或sendAsync??

这是我正在使用的代码。

 client.BaseAddress = new Uri("https://myservicehub.servicebus.windows.net");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Add("x-ms-version", "2015-01");
            client.DefaultRequestHeaders.Add("Authorization", sasToken);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/myservicehub/registrations/?api-version=2015-01");
             XmlDocument doc = new XmlDocument();
             doc.LoadXml("<entry xmlns='http://www.w3.org/2005/Atom'>" +
                 "<content type='application/xml'>"+
                 "<AppleRegistrationDescription xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'>"+
                 "<Tags>user</Tags>"+
                 "<DeviceToken>EEEEEE</DeviceToken>" +
                 "</AppleRegistrationDescription>"+
                 "</content>"+
                 "</entry>");
            request.Content = new StringContent(doc.ToString(), Encoding.UTF8, "application/atom+xml");
            HttpResponseMessage response = await client.SendAsync(request);

请求邮差

PostUrl:https://myservicehub.servicebus.windows.net/myservicehub/registrations/?api-version=2015-01

 <?xml version='1.0' encoding='utf-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'>
    <content type='application/xml'>
        <AppleRegistrationDescription xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'>
            <Tags>user</Tags>
            <DeviceToken>EEEEEE</DeviceToken>
        </AppleRegistrationDescription>
    </content>
</entry>

我做错了什么?

最好的,罗宾

通知中心Rest API -指定的资源描述无效

多亏了Dmitry p,问题就在这一行

 request.Content = new StringContent(doc.ToString(), Encoding.UTF8, "application/atom+xml");

改成:

 request.Content = new StringContent(doc.OuterXml, Encoding.UTF8, "application/atom+xml");