я пытался вставить изображение с моего телефона в базу данных mysql, используя универсальное приложение Windows и 2 php-файла. вот мой код xaml `
<TextBox x:Name="UserName" HorizontalAlignment="Left" Margin="143,23,0,0" TextWrapping="Wrap" Text="nameB" VerticalAlignment="Top" Height="2" Width="174"/> <TextBox x:Name="UserMail" HorizontalAlignment="Left" Margin="151,85,0,0" TextWrapping="Wrap" Text="emailB" VerticalAlignment="Top" Height="2" Width="174"/> <TextBox x:Name="UserImage" HorizontalAlignment="Left" Margin="153,218,0,0" TextWrapping="Wrap" Text="imageB" VerticalAlignment="Top" Height="2" Width="119"/> <PasswordBox x:Name="UserPassword" HorizontalAlignment="Left" Margin="185,145,0,0" VerticalAlignment="Top" Height="2" Width="141"/> <Button x:Name="UploadImage" Content="upload" HorizontalAlignment="Left" Margin="284,218,0,0" VerticalAlignment="Top" Click="upload_Click"/> <Button x:Name="SubmitUser" Content="submit" HorizontalAlignment="Left" Margin="242,297,0,0" VerticalAlignment="Top" Click="submit_Click"/> </Grid>`
и вот моя главная страница.xaml.cs
public sealed partial class MainPage : Page { HttpClient client = new HttpClient(); public MainPage() { this.InitializeComponent(); } private async void upload_Click(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file UserImage.Text = file.Name; } } private async void submit_Click(object sender, RoutedEventArgs e) { /* NameValueCollection UserInfo = new NameValueCollection(); UserInfo.Add("UserName", UserName.Text); UserInfo.Add("UserMail", UserMail.Text); UserInfo.Add("UserPassword", UserPassword.Password); UserInfo.Add("UserImage", UserImage.Text); */ ///*********///// String url = "http://172.19.241.135/tutorial/insertStudent.php"; var values = new List<KeyValuePair<String, String>> { new KeyValuePair<string, string>("UserName",UserName.Text), new KeyValuePair<string, string>("UserMail",UserMail.Text), new KeyValuePair<string, string>("UserPassword",UserPassword.Password), new KeyValuePair<string, string>("UserImage",UserImage.Text) }; HttpResponseMessage response = new HttpResponseMessage(); try { response = await client.PostAsync(url, new FormUrlEncodedContent(values)); if (response.IsSuccessStatusCode) { Debug.WriteLine(response.StatusCode.ToString()); var dialog = new MessageDialog("added succesfully "); await dialog.ShowAsync(); } else { // problems handling here string msg = response.IsSuccessStatusCode.ToString(); throw new Exception(msg); } } catch (Exception exc) { // .. and understanding the error here Debug.WriteLine(exc.ToString()); } } }
и я застрял сейчас, когда я пытался использовать телефонный код Windows, но я не могу найти замену для
byte[] insertuser= client.uploadValues("",values); client.Headers.Add("content_type","binary/octet_stream"); byte[] insertUserImage=client.uploadFile("",FileChooser.FileName) ;
кажется, что эти методы больше не доступны в универсальных приложениях Windows, любая помощь будет оценена