How to execute a PUT from a WPF .NET 4 application and get back a JSON string?

  • Thread starter Thread starter Richard.Haggard
  • Start date Start date
R

Richard.Haggard

Guest
I have a WPF application written in C# .NET 4.0 (but also has to work in .NET 3.5) that is using WebClient's UploadData (unsuccessfully) to pass data up to a local server and get a response.

I suspect that I'm doing something wrong with how the arguments are specified because a different call that just uses an address and an empty byte array works just fine to return a JSON encoded object. Here's one of many attempts I've made in order to get the thing to work:

try
{
string url = "http://127.0.0.1:4420/readlogs";
string values = "uid=haggard%40msn.com&mailid=14193de4%2Dc772%2D4ee2%2D8aa3%2D8d1b06cbf6f2&entries=50&desc=true&notifications_only=true";
byte[] bytes = Encoding.ASCII.GetBytes(values);
using (var webClient = new WebClient())
{
byte[] ba = webClient.UploadData( url, "PUT", bytes );
string resp = Encoding.ASCII.GetString( ba );
}
}
catch(Exception ex)
{
lblJSONResponse.Content = ex.ToString();
}


The result is an exception of "The remote server returned an error: (500) Internal Server Error."

What should I be doing differently?




Richard Lewis Haggard

Continue reading...
 
Back
Top