Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing querystring values not being assembled

  • Loading branch information...
commit 5c5789eb956fbd9336487539bf93fa2dacbd6827 1 parent 63bbb43
@johnsheehan johnsheehan authored
View
2  RestSharp/Http.Async.cs
@@ -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
3  RestSharp/Http.Sync.cs
@@ -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
15 RestSharp/Http.cs
@@ -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
33 RestSharp/RestClient.cs
@@ -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
4 restsharp.nuspec
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.