问题
I'm trying to read contacts using 32feet library for c#. I'm connecting my PC to mobile device via bluetooth, and when I try to execute this code always give me bad request error
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();
And in the constructor:
private BluetoothDeviceInfo localinfo = null;
public BluetoothDeviceInfo LocalInfo
{
get
{
return localinfo = (localinfo ?? new BluetoothDeviceInfo(BluetoothRadio.PrimaryRadio.LocalAddress));
}
}
What I'm doing wrong? Is the URI wrong, or I need a different Bluetooth?
回答1:
Though I am not an expert in 32feet, I know that the Name Header
of the GET
request retrieving vcard should be null
. Why don't you try using empty or null
URI?
Edit I found some statements that requires you to use obex-ftp instead of obex.
Remarks
For Object Exchange the method code is mapped to the equivalent HTTP style method. For example "PUT", "GET" etc. "PUT" is the default value. There is new support for GET as of version 2.5.
To use GET change the Method to " GET " and you must also use scheme " obex-ftp " in the URL instead of the usual " obex " -- unless you know that the default OBEX server you are connecting supports GET.
And it is cited from here.
Edit
Phonebook Access Similar to file transfer, but uses a target {0x79, 0x61, 0x35, 0xF0, 0xF0, 0xC5, 0x11, 0xD8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66}; phonebook entries can be listed (with various possible orderings and filters) and retrieved from certain directories under telecom/ using GET and SETPATH
--according to wikipedia you should put some specific UUID to TARGET
header when you connect to phonebook access
.
Like codes from here, you should not only specify PBAP Service UUID 0000112f-0000-1000-8000-00805f9b34fb
on RFCOMM level, but also have to specify target header UUID 0x79, 0x61, 0x35, (byte) 0xf0, (byte) 0xf0, (byte) 0xc5, 0x11, (byte) 0xd8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0c, (byte) 0x9a, 0x66
on OBEX level in type header.
来源:https://stackoverflow.com/questions/49094515/read-contacts-using-obex-in-c-sharp