【问题标题】:Read contacts using obex in c#在 c# 中使用 obex 读取联系人
【发布时间】:2018-08-12 04:00:34
【问题描述】:

我正在尝试使用 c# 的 32feet 库读取联系人。我正在通过蓝牙将我的 PC 连接到移动设备,当我尝试执行此代码时,总是给我错误的请求错误

LocalInfo.SetServiceState(BluetoothService.PhonebookAccessPce, true);
BluetoothAddress addr = BluetoothAddress.Parse("00:00:00:00:00:00");
BluetoothEndPoint rep = new BluetoothEndPoint(addr, BluetoothService.PhonebookAccessPse);
BluetoothClient cli = new BluetoothClient();
cli.Connect(rep);

Uri uri = new Uri(ObexUri.UriSchemeObex + "://" + addr + "/telecom/pb.vcf");
ObexWebRequest request = new ObexWebRequest(uri);
request.Method = "GET";
request.ContentType = "text/x-vCard";
ObexWebResponse resp = (ObexWebResponse)request.GetResponse();

在构造函数中:

private BluetoothDeviceInfo localinfo = null;
public BluetoothDeviceInfo LocalInfo
    {
        get
        {
            return localinfo = (localinfo ?? new BluetoothDeviceInfo(BluetoothRadio.PrimaryRadio.LocalAddress));
        }
    }

我做错了什么?是 URI 错误,还是我需要不同的蓝牙?

【问题讨论】:

    标签: c# bluetooth 32feet obex


    【解决方案1】:

    虽然我不是 32feet 方面的专家,但我知道 GET 请求检索 vcard 的 Name Header 应该是 null。为什么不尝试使用空或null URI?

    编辑我发现了一些要求您使用 obex-ftp 而不是 obex 的语句。

    备注

    对于对象交换,方法代码映射到等效的 HTTP 风格方法。例如“PUT”、“GET”等。“PUT”是默认值 价值。从 2.5 版开始,新增了对 GET 的支持。

    要使用 GET,请将方法更改为“GET”,并且您还必须使用方案 URL 中的“obex-ftp”而不是通常的“obex”——除非您 知道您连接的默认 OBEX 服务器支持 GET。

    并且引用自here

    编辑

    电话簿访问类似于文件传输,但使用目标 {0x79, 0x61, 0x35, 0xF0, 0xF0, 0xC5, 0x11, 0xD8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66};可以列出电话簿条目(具有各种 可能的排序和过滤器)并从某些目录中检索 在 Telecom/ 下使用 GET 和 SETPATH

    --根据维基百科,当您连接到 phonebook access 时,您应该将一些特定的 UUID 放入 TARGET 标头。

    here 中的代码一样,您不仅应在RFCOMM 级别指定PBAP 服务UUID 0000112f-0000-1000-8000-00805f9b34fb,还必须在类型标头中的OBEX 级别指定目标标头UUID 0x79, 0x61, 0x35, (byte) 0xf0, (byte) 0xf0, (byte) 0xc5, 0x11, (byte) 0xd8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0c, (byte) 0x9a, 0x66

    【讨论】:

    • 您好,感谢您的回答。使用空或空 URI 给我同样的错误:System.Net.WebException: 'GET failed with code: BadRequest, Final'
    • 你有任何可以工作的例子吗?非常感谢您的帮助
    • 试试这个。 [1]:stackoverflow.com/questions/48872112/… 将“”修补为空。我必须了解更多关于 32feet 的信息才能发布更好的答案。
    • 感谢您的回复。使用两者都会给我套接字异常。我不知道我使用的 uri ("telecom/pb.vcf") 是否正确...
    • 根据维基百科 (en.m.wikipedia.org/wiki/OBject_EXchange) 是正确的 uri。
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多