Permalink
Browse files

Fixing querystring values not being assembled

  • Loading branch information...
1 parent 63bbb43 commit 5c5789eb956fbd9336487539bf93fa2dacbd6827 @johnsheehan johnsheehan committed Jan 6, 2011
Showing with 36 additions and 21 deletions.
  1. +1 −1 RestSharp/Http.Async.cs
  2. +1 −2 RestSharp/Http.Sync.cs
  3. +0 −15 RestSharp/Http.cs
  4. +32 −1 RestSharp/RestClient.cs
  5. +2 −2 restsharp.nuspec
View
@@ -77,7 +77,7 @@ private void GetStyleMethodInternalAsync(string method, Action<HttpResponse> cal
{
try
{
- var url = AssembleUrl();
+ var url = Url;
var webRequest = ConfigureAsyncWebRequest(method, url);
webRequest.BeginGetResponse(result => ResponseCallback(result, callback), webRequest);
}
View
@@ -81,8 +81,7 @@ public HttpResponse Delete()
private HttpResponse GetStyleMethodInternal(string method)
{
- var url = AssembleUrl();
- var webRequest = ConfigureWebRequest(method, url);
+ var webRequest = ConfigureWebRequest(method, Url);
return GetResponse(webRequest);
}
View
@@ -222,21 +222,6 @@ private void AppendCookies(HttpWebRequest webRequest)
}
}
- private Uri AssembleUrl()
- {
- string url = Url.ToString();
- if (HasParameters)
- {
- if (url.EndsWith("/"))
- {
- url = url.Substring(0, url.Length - 1);
- }
- var data = EncodeParameters();
- url = string.Format("{0}?{1}", url, data);
- }
- return new Uri(url);
- }
-
private string EncodeParameters()
{
var querystring = new StringBuilder();
View
@@ -23,6 +23,7 @@
using System.Xml.Linq;
using RestSharp.Deserializers;
using RestSharp.Extensions;
+using System.Text;
namespace RestSharp
{
@@ -274,7 +275,37 @@ public Uri BuildUri(RestRequest request)
assembled = assembled.Substring(1);
}
- return new Uri(string.Format("{0}/{1}", BaseUrl, assembled));
+ assembled = string.Format("{0}/{1}", BaseUrl, assembled);
+
+ if (request.Method != Method.POST && request.Method != Method.PUT)
+ {
+ // build and attach querystring if this is a get-style request
+ if (request.Parameters.Any(p => p.Type == ParameterType.GetOrPost))
+ {
+ if (assembled.EndsWith("/"))
+ {
+ assembled = assembled.Substring(0, assembled.Length - 1);
+ }
+
+ var data = EncodeParameters(request);
+ assembled = string.Format("{0}?{1}", assembled, data);
+ }
+ }
+
+ return new Uri(assembled);
+ }
+
+ private string EncodeParameters(RestRequest request)
+ {
+ var querystring = new StringBuilder();
+ foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
+ {
+ if (querystring.Length > 1)
+ querystring.Append("&");
+ querystring.AppendFormat("{0}={1}", p.Name.UrlEncode(), ((string)p.Value).UrlEncode());
+ }
+
+ return querystring.ToString();
}
private void ConfigureHttp(RestRequest request, IHttp http)
View
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>RestSharp</id>
- <version>100.0</version>
+ <version>100.1</version>
<authors>John Sheehan, RestSharp Community</authors>
<owners>John Sheehan</owners>
<description>Simple REST and HTTP API Client</description>
@@ -11,7 +11,7 @@
<licenseUrl>https://github.com/johnsheehan/RestSharp/blob/master/LICENSE.txt</licenseUrl>
<iconUrl>http://restsharp.org/wp-content/uploads/restsharp-icon-32.png</iconUrl>
<dependencies>
- <dependency id="Newtonsoft.Json" />
+ <dependency id="Newtonsoft.Json" version="3.5.8" />
</dependencies>
<tags>REST HTTP API</tags>
</metadata>

0 comments on commit 5c5789e

Please sign in to comment.