0

I would like to send file to a web service with other parametrs
Like this :

param1=value1&param2=value2&param3=IMAGE_FILE

how can i do this in C#
I try this :

&param3=Convert.ToBase64String(File.ReadAllBytes(txtlogo.Text))

but thats not work..
so have any solution ?

Update :

Also I try to use from HttpContent like this (i don't know it's correct or no )

HttpContent stringContent = new StringContent("param1=param1&param2=param2");
            FileStream file = new FileStream(txtlogo.Text, FileMode.Open);
            HttpContent fileStreamContent = new StreamContent(file);
            using (var client = new HttpClient())
            using (var formData = new MultipartFormDataContent())
            {
                formData.Add(stringContent, "param1", "param1");
                formData.Add(fileStreamContent, "file1", "file1");
                var response = client.PostAsync("url", formData).Result;
                if (!response.IsSuccessStatusCode)
                {
                   string ss = "s";
                }
                string my = response.Content.ReadAsStringAsync().Result; 
            }

and server don't receive any data with POST ...

MrUnknow
  • 359
  • 3
  • 18

1 Answers1

-1

try with get method (simple)

    try
{
    using (var wc = new WebClient())
    {
        string url = "https://url.com/index.php?x=1222&y=filebase64-sdfsdfsdfsdfsdfsdfsdfsdfsd";
        // Get account from accessToken
        response = wc.DownloadString(url);
    }
}
catch (Exception ee)
{
    Console.WriteLine("Coś nie tak z pobieraniem kont");
}
  • And tutorial http://www.terminally-incoherent.com/blog/2008/05/05/send-a-https-post-request-with-c/ –  Feb 26 '17 at 18:27