View the URL before submission

3,061 views
Skip to first unread message

gary lucas

unread,
May 4, 2012, 2:10:17 PM5/4/12
to rest...@googlegroups.com
There's good odds I'm being thick, but I can't seem to find a place where I can see the full request before submitting (or after).

IE: "http:somewhere.a.com/rest/method?par1=x&par2=y"

I'm working with an API that requires me to submit the hash of the URL.

Thank you very much,

Gary Lucas

gary lucas

unread,
May 4, 2012, 2:39:07 PM5/4/12
to rest...@googlegroups.com
And of course after submitting the question the answer became obvious, I was using the wrong method to add arguments to the request.

Gary

John Sheehan

unread,
May 5, 2012, 1:48:01 AM5/5/12
to rest...@googlegroups.com
I'm assuming you found RestClient.BuildUri(RestRequest) but you should
post your solution for others.

gary lucas

unread,
May 7, 2012, 5:04:08 PM5/7/12
to rest...@googlegroups.com
Sure:

Because our partner decided that the order of the parameters matter:

foreach (string key in parameters.Keys)
{
   request.AddParameter(new Parameter() { Name = key, Type = ParameterType.GetOrPost, Value = UrlEncodeUpperCase(parameters[key]) });
}


var urlToGenerateSignature = client.BuildUri(request).AbsoluteUri;


Then gets us the URI.

gary lucas

unread,
May 9, 2012, 12:45:58 AM5/9/12
to rest...@googlegroups.com
I do have one mostly unrelated question.

The API am integrating with requires a call in the form of:
https://blah.b/method?arg1=a&arg2=b
PUT

I notice that the RestSharp client doesn't append parameters except on Get.

I'm not experienced enough in Rest to have a strong opinion here, but it does strike me as an odd limitation.

I'm wondering what the rationalization is.

Gary

John Sheehan

unread,
May 14, 2012, 7:25:12 PM5/14/12
to rest...@googlegroups.com
See: https://groups.google.com/forum/#!topic/restsharp/IChKmMNWLsg

This will likely be easier to accomplish in an upcoming version.
Though someone needs to build it and I don't have any time for the
next few months.

Marty Neal

unread,
Oct 30, 2012, 7:53:31 AM10/30/12
to rest...@googlegroups.com
I just ran into the same issue.  This is the method I created to do what I wanted:

    public static class RestSharpExts
    {
        /// <summary>
        /// Assembles URL to call based on parameters, method and resource
        /// </summary>
        /// <param name="client">RestClient performing the execution</param>
        /// <param name="request">RestRequest to execute</param>
        /// <returns>Assembled System.Uri</returns>
        /// <remarks>
        /// RestClient's BuildUri purposefully leaves off the parameters from the uri it builds when the request 
        /// is a POST, PUT, or PATCH.  This extension method aims to undo this feature for debugging reasons
        /// </remarks>
        public static Uri BuildDebugUri(this IRestClient client, IRestRequest request)
        {
            var uri = client.BuildUri(request);
            if (request.Method != Method.POST &&
                request.Method != Method.PUT &&
                request.Method != Method.PATCH)
            {
                return uri;
            }
            else
            {
                var queryParameters = from p in request.Parameters
                                      where p.Type == ParameterType.GetOrPost
                                      select string.Format("{0}={1}", Uri.EscapeDataString(p.Name), Uri.EscapeDataString(p.Value.ToString()));
                if (!queryParameters.Any())
                {
                    return uri;
                }
                else
                {
                    var path = uri.OriginalString.TrimEnd('/');
                    var query = string.Join("&", queryParameters);
                    return new Uri(path + "?" + query);

Tarik Jebbour

unread,
May 3, 2016, 4:07:58 PM5/3/16
to RestSharp
Thanks man!
Reply all
Reply to author
Forward
0 new messages