public ResponseDto GetJsonByPost() { HttpClient client = new HttpClient("https://ai.baidu.com") { Headers = new Dictionary <string, string>() { { "Cookie", "" } } }; var file = new FileInfo("D:/jetbrains.png"); var array = file.OpenRead().ConvertToByteArray(); client.AddFile(new RequestMultDataParam("image", file.Name, array, "image/png")); var res = client.GetJsonByPost <ResponseDto>($"aidemo", new { image_url = "", type = "animal", show = true }); return(res); }
/// <summary> /// 发送数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Bt_SendData_Click(object sender, RoutedEventArgs e) { Uri serverUri = null; try { serverUri = new Uri(this.tb_SendUrl.Text); } catch { MessageBox.Show("目标主机不正确,无法发送数据!", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); return; } if (comboBoxPostGetChoice.Text == "POST") { httpClient.MethodInit(Methods.POST); //数据 if (checkBox_PostData.IsChecked == true) { DockPanel dockPanel = groupBox_PostData.Content as DockPanel; if (dockPanel == null) { return; } StackPanel stackPanel = dockPanel.Children[1] as StackPanel; if (stackPanel == null) { return; } foreach (var item in stackPanel.Children) { DockPanel dockPanel_1 = item as DockPanel; if (dockPanel_1 == null) { continue; } StackPanel stackPanel_11 = dockPanel_1.Children[0] as StackPanel; if (stackPanel_11 == null) { continue; } StackPanel stackPanel_12 = dockPanel_1.Children[2] as StackPanel; if (stackPanel_12 == null) { continue; } RadioButton radioButton = stackPanel_11.Children[0] as RadioButton; if (radioButton == null) { continue; } // Content="字符串" if (radioButton.IsChecked == true) { TextBox textBox = stackPanel_12.Children[0] as TextBox; if (textBox == null) { continue; } httpClient.AddString(textBox.Text); } else { TextBox textBox = stackPanel_12.Children[1] as TextBox; if (textBox == null) { continue; } httpClient.AddHex(textBox.Text); } } } //字段 if (checkBox_PostParam.IsChecked == true) { DockPanel dockPanel = groupBox_PostParam.Content as DockPanel; if (dockPanel == null) { return; } StackPanel stackPanel = dockPanel.Children[1] as StackPanel; if (stackPanel == null) { return; } foreach (var item in stackPanel.Children) { DockPanel dockPanel_1 = item as DockPanel; if (dockPanel_1 == null) { continue; } TextBox textBox0 = dockPanel_1.Children[0] as TextBox; if (textBox0 == null) { continue; } TextBox textBox3 = dockPanel_1.Children[3] as TextBox; httpClient.AddParam(textBox0.Text, textBox3.Text); } } //文件 if (checkBox_PostFile.IsChecked == true) { DockPanel dockPanel = groupBox_PostFile.Content as DockPanel; if (dockPanel == null) { return; } StackPanel stackPanel = dockPanel.Children[1] as StackPanel; if (stackPanel == null) { return; } foreach (var item in stackPanel.Children) { DockPanel dockPanel_1 = item as DockPanel; if (dockPanel_1 == null) { continue; } TextBox textBox2 = dockPanel_1.Children[2] as TextBox; if (textBox2 == null) { continue; } httpClient.AddFile(textBox2.Text); } } } else { httpClient.MethodInit(Methods.GET); //数据 if (checkBox_GetData.IsChecked == true) { DockPanel dockPanel = groupBox_GetData.Content as DockPanel; if (dockPanel == null) { return; } StackPanel stackPanel = dockPanel.Children[1] as StackPanel; if (stackPanel == null) { return; } foreach (var item in stackPanel.Children) { DockPanel dockPanel_1 = item as DockPanel; if (dockPanel_1 == null) { continue; } TextBox textBox = dockPanel_1.Children[2] as TextBox; if (textBox == null) { continue; } httpClient.AddString(textBox.Text); } } //字段 if (checkBox_GetParam.IsChecked == true) { DockPanel dockPanel = groupBox_GetParam.Content as DockPanel; if (dockPanel == null) { return; } StackPanel stackPanel = dockPanel.Children[1] as StackPanel; if (stackPanel == null) { return; } foreach (var item in stackPanel.Children) { DockPanel dockPanel_1 = item as DockPanel; if (dockPanel_1 == null) { continue; } TextBox textBox0 = dockPanel_1.Children[0] as TextBox; if (textBox0 == null) { continue; } TextBox textBox3 = dockPanel_1.Children[3] as TextBox; if (textBox3 == null) { continue; } httpClient.AddParam(textBox0.Text, textBox3.Text); } } } httpClient.Start(); }