async public void ConnectToNetwork() { string hostname = selectedDevice.Location.Host; int port = selectedDevice.Location.Port; HttpResponseMessage metaResponse = await SoapRequestHelper.MakeRequest(hostname, port, "GetMetaInfo", "urn:Belkin:service:metainfo:1", "/upnp/control/metainfo1"); string metaInfoResponse = await metaResponse.Content.ReadAsStringAsync(); int indexOfStartMetaInfo = metaInfoResponse.IndexOf("<MetaInfo>"); int indexOfEndMetaInfo = metaInfoResponse.IndexOf("</MetaInfo>"); string metainfo = metaInfoResponse.Substring(indexOfStartMetaInfo + 10, indexOfEndMetaInfo - (indexOfStartMetaInfo + 10)); string encryptedPassword = EncryptPassword(Password, metainfo); encryptedPassword += encryptedPassword.Length.ToString("x") + (Password.Length < 16 ? "0" : "") + Password.Length.ToString("x"); HttpResponseMessage response = await SoapRequestHelper.MakeRequest(hostname, port, "ConnectHomeNetwork", wifiSetupService.ServiceType, wifiSetupService.ControlURL, new Tuple <string, object>("auth", AccessPoint.Auth), new Tuple <string, object>("channel", AccessPoint.Channel), new Tuple <string, object>("encrypt", AccessPoint.Encrypt), new Tuple <string, object>("password", encryptedPassword), new Tuple <string, object>("ssid", AccessPoint.Ssid)); if (response.IsSuccessStatusCode) { await Task.Delay(2000); HttpResponseMessage statusResponse = await SoapRequestHelper.MakeRequest(hostname, port, "GetNetworkStatus", wifiSetupService.ServiceType, wifiSetupService.ControlURL); Status = await statusResponse.Content.ReadAsStringAsync(); if (statusResponse.IsSuccessStatusCode) { HttpResponseMessage closeResponse = await SoapRequestHelper.MakeRequest(hostname, port, "CloseSetup", wifiSetupService.ServiceType, wifiSetupService.ControlURL); if (closeResponse.IsSuccessStatusCode) { Error = "Success!"; } else { Error = await response.Content.ReadAsStringAsync(); } } else { Error = await statusResponse.Content.ReadAsStringAsync(); } } else { Error = await response.Content.ReadAsStringAsync(); } }
async private void GetApList() { string hostname = SelectedDevice.Location.Host; int port = SelectedDevice.Location.Port; HttpResponseMessage response = await SoapRequestHelper.MakeRequest(hostname, port, "GetApList", wifiSetupService.ServiceType, wifiSetupService.ControlURL); string responseText = await response.Content.ReadAsStringAsync(); int indexOfApListStart = responseText.IndexOf("<ApList>"); int indexOfApListEnd = responseText.IndexOf("</ApList>"); AccessPointParser app = new AccessPointParser(responseText.Substring(indexOfApListStart + 8, indexOfApListEnd - (indexOfApListStart + 8))); IEnumerable <AccessPoint> aps = app.ParseAccessPoints(); AccessPoints = new ObservableCollection <AccessPoint>(aps); }