0

I want to send POST with parameters, but I don't know how to do it.

My code:

 Uri resourceAddress = new Uri("http://web.com/geo");
 try
 {
    HttpResponseMessage response=await httpClient.PostAsync(resourceAddress,
        new HttpStringContent("")).AsTask(cts.Token);
 }
 catch (Exception ex) { }
 finally { }

How can I send a post with this code like: { latitude:-1.323141, lng:24.42342 }

BrunoLM
  • 97,872
  • 84
  • 296
  • 452
Javierif
  • 632
  • 1
  • 6
  • 18

1 Answers1

1

You populate the HttpContent with the key/values you want to send over.

Specifically:

Uri resourceAddress = new Uri("http://web.com/geo");
var values = new Dictionary<string, double>
{
   { "latitude", -1.323141 },
   { "lng", 24.42342 }
};

var content = new FormUrlEncodedContent(values);

try{
    HttpResponseMessage response=await httpClient.PostAsync(resourceAddress,
         content).AsTask(cts.Token);
 } catch (Exception ex){
 }finally{

 }
gnalck
  • 972
  • 6
  • 12