how to send parameters via restsharp RAW?

1,349 views
Skip to first unread message

Estivenson Carvajal Salazar

unread,
Aug 27, 2012, 5:23:03 PM8/27/12
to rest...@googlegroups.com
how to send parameters via restsharp in format RAW?


John Sheehan

unread,
Aug 27, 2012, 7:40:34 PM8/27/12
to rest...@googlegroups.com
You're going to need to provide more information.

Estivenson Carvajal Salazar

unread,
Aug 28, 2012, 8:51:11 AM8/28/12
to rest...@googlegroups.com
I have this RAW:

{"PetitionType":"3","PageNumber":"1","Parameter":"APPLE","Rows":"12"}

Tthese are the parameters that are passed to the POST method that returns a list of products.

This is the code I have right now, but I've tried everything:

var client = new RestClient(ConfigurationManager.AppSettings["ServidorWS"]);
                var request = new RestRequest("/rest/product/get", Method.POST);                                
                request.AddHeader("Content-Type", "application/json; charset=UTF-8");
                string variable = "{'PetitionType':'3','PageNumber':'1','Parameter':'APPLE','Rows':'12'}";
                var serializer = new JsonSerializer();
                serializer.Serialize(variable);
                request.AddBody(variable);   
                var response = client.Execute(request);
                var contenido = response.Content;

Patrick Steele

unread,
Aug 28, 2012, 9:05:14 AM8/28/12
to rest...@googlegroups.com
Is the code not working? What errors are you getting? Have you used
something like Fiddler to see what is being sent?

---
Patrick Steele
http://weblogs.asp.net/psteele

Estivenson Carvajal Salazar

unread,
Aug 28, 2012, 9:12:35 AM8/28/12
to rest...@googlegroups.com
The error is "Bad Request" and I have not used anything of what you say...


El lunes, 27 de agosto de 2012 16:23:03 UTC-5, Estivenson Carvajal Salazar escribió:

Estivenson Carvajal Salazar

unread,
Aug 28, 2012, 9:19:47 AM8/28/12
to rest...@googlegroups.com


I am using this application for testing, what I need is to make this request with these parameters raw, with RestSharp

Patrick Steele

unread,
Aug 28, 2012, 9:34:49 PM8/28/12
to rest...@googlegroups.com
Sorry to ask this, but you keep using the term "raw" when describing these parameters.  What exactly are you referring to?  What do you mean by "raw parameters"?

Patrick Steele

unread,
Aug 28, 2012, 9:44:10 PM8/28/12
to rest...@googlegroups.com
Oh, ok.  I see what you're doing.  I originally didn't have the picture displayed.

In the code you posted earlier, you rook a JSON string:


{"PetitionType":"3","PageNumber":"1","Parameter":"APPLE","Rows":"12"}

And used the JSON serializer on it -- but the serializer is designed to serialize objects, not strings.  It would probably be easiest to just create an object with the same properties and use the json serializer on that object:

public class Data
{
    public string PetitionType {get;set;}
    public string PageNumber {get;set;}
    public string Parameter {get;set;}
    public string Rows {get;set;}
}

var data = new Data { PetitionType = "3", PageNunber = "1", Parameter = "APPLE", Rows = "12" };

Then use the json serializer on "data", not the "raw" string.
On Tue, Aug 28, 2012 at 9:19 AM, Estivenson Carvajal Salazar <styve...@hotmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages