0

I want to send data to a server using POST in c# using WebClient method. The data to be send has a key value pair. key: param value: [0.5,0.2,0.02]

How to send this kind of data?

  • Possible duplicate of [How to post data to specific URL using WebClient in C#](http://stackoverflow.com/questions/5401501/how-to-post-data-to-specific-url-using-webclient-in-c-sharp) – Matias Cicero Oct 24 '16 at 13:59
  • Have you tried to do this yourself at all? – Hank Oct 24 '16 at 13:59
  • string result = ""; using (var client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "application/json"; result = client.UploadString(url, "POST", json); } Console.WriteLine(result); – Vivek Nuna Oct 24 '16 at 14:11
  • I have tried all this already. The post data needs to be in [1,2,3] form. So how to make the data appear in the POST url in the first place. – user3323171 Oct 24 '16 at 19:31
  • @viveknuna can you tell me how to write that json part. Will it be in my case something like this: string json="param:[0.5,0.2,0.02]"; – user3323171 Oct 24 '16 at 19:52
  • it will be like this { "param value": [0.5, 0.2, 0.02] } – Vivek Nuna Oct 24 '16 at 19:54
  • string postData = "{\"param value\": [0.5, 0.2, 0.02]}"; – Vivek Nuna Oct 24 '16 at 19:56
  • ok thanks I will try it and will let you know by tomorrow – user3323171 Oct 24 '16 at 20:04
  • No it's not working. – user3323171 Oct 25 '16 at 07:56
  • Actually I want to send a command to camera whose json string is like this: {"method" : "ptz.move", "session" : 2030461149, "params" : {"screen" : [0.5032958984375,0.5662841796875,0.11682510375976562]}, "id" : 83}:"" How to send this. The server is always returning Error 500. It will be better if I can send it directly through url – user3323171 Oct 25 '16 at 07:58

0 Answers0