last day (14 days later) » 

12:38 AM
2
Q: Replicating this PUT request in RestSharp

MattBelow is what the request looks like in the web app. Request URL:http://myurl.com/rest Request Method:PUT Status Code:200 Ok Request Headersview source Accept:*/* Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Length:60 Content-Type:application/j...

 
wal
how is it not successful? what are the differences between what you want and what you currently get?
 
It should be updating the backend value for dnd to true like the web app. At the moment it just doesn't update that value. And there's no response returned for either a successful or unsuccessful call. I'll get a wireshark capture and add it to the question in a moment.
 
wal
fiddler capture will be better
I do note your JSON payload uses single quotes for strings 'table':'users' instead of double quotes which is correct: "table":"users"
 
I've added the Fiddler capture of both the web app and c# app. It seems that the data I'm adding via RestSharp isn't being added..
@wal I've tried using double quotes (escaped) but it does not work either.
 
wal
Your exact code produces a different outcome for me using Restsharp 103.2 - see imgur.com/3w9tYes Interestingly your Content-Type is still text/xml - that is definitely wrong so perhaps you need to recompile? can you change something else to ensure that everything is recompiling? perhaps a Console.Out statement
 
12:38 AM
Well that's disconcerting.
I'm able to send objects but the string doesn't seem to show up. How would you format the data into a C# object? Not sure how to add the array part after settings.
 
wal
hi mate u there?
 
Yes, thanks for your help.
 
wal
am not sure there will be much difference converting your string into a c# object...
you need to get that content type part working correctly first
 
The thing is, all my other REST calls are currently sending objects. This is the only one sending a string but that was only because I couldn't format the object properly, so I figured I'd just send it as a json string.
If I do change it to an object, content-type seems to set it's self correctly and the data shows in the fiddler capture
 
wal
what did u try in terms of getting it to work with a C# object?
 
12:42 AM
        object myObj = new { table = "users", settings = "array should go here" };
        request.AddBody(myObj);
 
wal
ok try this... (moment)
request.AddBody(new { table = "users", settings = new[] { new NameValuePair() { name = "dnd", value = "true" } } });
 
Trying now.
 
wal
u need to define that class
public class NameValuePair
{
public string name { get; set; }
public string value { get; set; }
}
 
Incredible. Yes, it's worked. It updated the backend and the data is now identical to the web app.

{"table":"users","settings":[{"name":"dnd","value":"true"}]}
It's a little odd though the string wasn't showing in 105 but it was for you.
Thanks for your help, you should add an answer so I can mark it as correct.
 
wal
ok will do cheers!
thanks!
for the record you can do it without NameValuePair as you can define another dynamic class but its a little clearer that way
 
12:53 AM
Yeh this will work. I'll have to replicate this functionality a fair bit and it's easy to follow. Cheers again.
 
wal
actually its nicer without it :) have updated it
if u have well defined objects best to use them instead of dynamic classes
 
Yeh you're right, that is better :)
 
wal
i got the idea from you actually
as did it 100% with classes initially
learn something every day :)
 
Glad I could contribute :P
 
wal
bibi for now
 

last day (14 days later) »