c# HttpClient прикрепить картинку при отправке POST запроса

Искал пробовал\пробовал информацию в интернете, получал одни ошибки. Нужно отправить POST запрос с параметрами, одним из параметров передать картинку.

Мой код:

var baseAddress = new Uri("domain.com");

using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
    var content = new FormUrlEncodedContent(new[]
    {
            new KeyValuePair<string, string>("avtoriz_user_adv", "off"),
            new KeyValuePair<string, string>("name_adv",  Title),
            new KeyValuePair<string, string>("text_adv", Msg),
            new KeyValuePair<string, string>("key_words", ""),
            new KeyValuePair<string, string>("time_adv", "month"),
            new KeyValuePair<string, string>("img_adv[]", "(binary)"),
            new KeyValuePair<string, string>("imagesValue", "ТУТ ДОЛЖНА БЫТЬ КАРТИНКА.JPG"),
            new KeyValuePair<string, string>("captcha", getCaptcha(convertIMG.Base64ToImage(photobytes))),
            new KeyValuePair<string, string>("PHPSESSID", PHPSESSID),
            new KeyValuePair<string, string>("add_maps", "off"),
            new KeyValuePair<string, string>("longitude", "0"),
            new KeyValuePair<string, string>("latitude", "0"),
            new KeyValuePair<string, string>("is_new_adv", "alkdt"),
    });
    var result = await client.PostAsync("uploadfile_new.php", content);
    result.EnsureSuccessStatusCode();

    return await result.Content.ReadAsStringAsync();
}

Тут должно быть изображение

new KeyValuePair<string, string>("imagesValue", "ТУТ ДОЛЖНА БЫТЬ КАРТИНКА.JPG"),

Изображение нужно передавать как byte[]? KeyValuePair принимает только string.

В примерах что находил изображение передавали на сервер без дополнительных параметров. Как это сделать? Спасибо:)


Ответы (0 шт):