Different behavior between direct call and RESTsharp

568 views
Skip to first unread message

Jean-Pierre Pasquet

unread,
Apr 29, 2012, 5:06:40 PM4/29/12
to RestSharp
I have a strange problem when i call a webservice like this in my
navigator :

http://xxxxxxxx/xxxxxx/xxxx/users?mail=xx...@xxxx.fr&hash=e67bd01b34b2febcfe4140e5362173020f61b404&salt=sel&client=testapi&code=QPAylQEBXXsgasn9CIdJ7nsx0QU

that work, the web service send me information

but when i call with this C# code(simple test for the moment)


var client = new RestClient();
client.BaseUrl = "http://xxxxxxxx/xxxxxx/xxxx";
//client.Authenticator = new
HttpBasicAuthenticator("username", "password");

var request = new RestRequest(Method.GET);
request.Resource = "users";
request.AddParameter("mail", "xx...@xxxx.fr");
request.AddParameter("hash",
"e67bd01b34b2febcfe4140e5362173020f61b404");
request.AddParameter("salt", "sel");
request.AddParameter("__client", "testapi");
request.AddParameter("__code", "QPAylQEBXXsgasn9CIdJ7nsx0QU");


RestResponse response = client.Execute(request);

Response.Write(response.Content);

the web service, return "Unauthorized", this error is return when the
__code who is signature is not good, but these are the same parameters

But this code works :

RestResponse response = client.Execute(request);
//Response.Write(response.Headers);
Response.Write(response.Content);

Response.Write(HttpGet(


"http://xxxxxxxx/xxxxxx/xxxx/users?
mail=tes...@test.com&hash=7d2b6ab59c517b70dfd238f659fc67e2e5d23bb9&salt=sel&__client=testapi&__code=oVS13dGZe8sdH9OnZ6qovsGFcvI"




));


static string HttpGet(string url)
{
HttpWebRequest req = WebRequest.Create(url)
as HttpWebRequest;
string result = null;
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
return result;
}



I asked the url the server is getting, but I do not know when I have
the answer...


Any idea?

Thank!



I already asked, but I do not know when I have the answer

Andrew Young

unread,
Apr 30, 2012, 12:37:21 PM4/30/12
to rest...@googlegroups.com
Use restClient.BuildUri(request) and compare the uri it returns with the one you expect.

Jean-Pierre Pasquet

unread,
May 2, 2012, 3:41:33 AM5/2/12
to RestSharp
The url return is good(when i copy/past to navigator and that work).
but the the web service continue return Unauthorized

I do not understand why, i can send you th real url and parameter by
email if you want




On 30 avr, 18:37, Andrew Young <andrewdyo...@gmail.com> wrote:
> Use restClient.BuildUri(request) and compare the uri it returns with the
> one you expect.
>
> On Sun, Apr 29, 2012 at 2:06 PM, Jean-Pierre Pasquet
> <jp.pasq...@gmail.com>wrote:
>
>
>
> > I have a strange problem when i call a webservice like this in my
> > navigator :
>
> > http://xxxxxxxx/xxxxxx/xxxx/users?mail=x...@xxxx.fr&hash=e67bd01b34b2febcfe4140e5362173020f61b404&salt=sel&client=test­api&code=QPAylQEBXXsgasn9CIdJ7nsx0QU
>
> > that work, the web service send me information
>
> > but when i call with this C# code(simple test for the moment)
>
> >        var client = new RestClient();
> >        client.BaseUrl = "http://xxxxxxxx/xxxxxx/xxxx";
> >        //client.Authenticator = new
> > HttpBasicAuthenticator("username", "password");
>
> >        var request = new RestRequest(Method.GET);
> >        request.Resource = "users";
> >        request.AddParameter("mail", "x...@xxxx.fr");
> >        request.AddParameter("hash",
> > "e67bd01b34b2febcfe4140e5362173020f61b404");
> >        request.AddParameter("salt", "sel");
> >        request.AddParameter("__client", "testapi");
> >        request.AddParameter("__code", "QPAylQEBXXsgasn9CIdJ7nsx0QU");
>
> >        RestResponse response = client.Execute(request);
>
> >        Response.Write(response.Content);
>
> > the web service, return "Unauthorized", this error is return when the
> > __code who is signature is not good, but these are the same parameters
>
> > But this code works :
>
> >            RestResponse response = client.Execute(request);
> >            //Response.Write(response.Headers);
> >            Response.Write(response.Content);
>
> >            Response.Write(HttpGet(
>
> >                "http://xxxxxxxx/xxxxxx/xxxx/users?
> > mail=test...@test.com
> > &hash=7d2b6ab59c517b70dfd238f659fc67e2e5d23bb9&salt=sel&__client=testapi&__­code=oVS13dGZe8sdH9OnZ6qovsGFcvI"

Andrew Young

unread,
May 2, 2012, 12:35:06 PM5/2/12
to rest...@googlegroups.com
Just curious. How is the code value calculated?
Reply all
Reply to author
Forward
0 new messages