我需要从代码中删除保存的wifi配置文件,以便再次启用SoftAP。根据ms docs,无法删除配置文件,只能断开连接。这不可能吗?Ms的wifi文档 https://docs.microsoft.com/zh-cn/uwp/api/windows.devices.wifi.wifiadapter设备门户API https://docs.microsoft.com/de-ch/windows/mixed-reality/device-portal-api-reference#wifi-management但是对于删除wifi配置文件,我从API中找不到404。根据上面链接的API文档,该请求应该可以。这是我删除wifi配置文件的代码 // API creds string username = "Administrator"; string password = "p@ssw0rd // API request URIs string apiUri = "http://192.168.1.15:8080/api/wifi/network"; // WiFi details string wifiInterface = string.Empty; string wifiProfile = string.Empty; // WiFi access WiFiAccessStatus wifiAccess = await WiFiAdapter.RequestAccessAsync(); if (wifiAccess == WiFiAccessStatus.Allowed) { // Get WiFi adapter IReadOnlyList<WiFiAdapter> wifiAdapterResult = await WiFiAdapter.FindAllAdaptersAsync(); WiFiAdapter wifiAdapter = wifiAdapterResult[0]; // Get conn profile / details ConnectionProfile profile = await wifiAdapter.NetworkAdapter.GetConnectedProfileAsync(); wifiInterface = profile.NetworkAdapter.NetworkAdapterId.ToString(); wifiProfile = profile.ProfileName; } // API creds PasswordCredential credentials = new PasswordCredential("login", username, password); // HttpClient filter HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); filter.CookieUsageBehavior = HttpCookieUsageBehavior.NoCookies; filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent; filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache; filter.ServerCredential = credentials;要解决此问题,自内部版本17763起,有一种新方法可直接从可用代码中删除WiFi配置文件bool canDelete = wifiProfile.CanDelete;if (canDelete){ ConnectionProfileDeleteStatus deleteStatus = await wifiProfile.TryDeleteAsync();}
3 回答
HUH函数
TA贡献1836条经验 获得超4个赞
最近一直在使用Windows设备门户API,并且遇到了这篇文章。您的代码得到404响应的原因是因为在API URI中,&profile=
期望的是Base64值,而不是您使用的文本字符串。将配置文件名称编码为Base64后,它应该可以使用。
我相信这在MS的设备门户文档中没有明确说明,因为我只是在删除WIFI配置文件时使用Web浏览器调试器检查Windows Device Portal网页发现了这一点。
- 3 回答
- 0 关注
- 183 浏览
添加回答
举报
0/150
提交
取消