Note that there are some explanatory texts on larger screens.

plurals
  1. POURL sometimes not being properly encoded - threading issue?
    text
    copied!<p>I am working on a Windows Form application in C# and have a method like the following which is being accessed by multiple threads (precisely, by multiple background workers):</p> <pre><code>public Uri signURL(OAuthToken token, string url) { UriBuilder builder = new UriBuilder(addOAuthParameters(url)); NameValueCollection query = HttpUtility.ParseQueryString(builder.Query); query.Set("oauth_consumer_key", consumerKey); /* * &amp; sometimes not replaced by %26 */ query.Set("oauth_signature", consumerSecret + "&amp;" + token.Secret); query.Set("oauth_token", token.Token); builder.Query = query.ToString(); return builder.Uri; } </code></pre> <p>I use this method to sign an arbitrary URL with some required OAuth parameters and afterwards do an HttpWebRequest to retrieve the content.</p> <p><strong>Edit 1:</strong> Here is the content of the addOAuthParameter method:</p> <pre><code>private Uri addOAuthParameters(string uri) { UriBuilder builder = new UriBuilder(uri); NameValueCollection query = HttpUtility.ParseQueryString(builder.Query); query.Set("oauth_signature_method", "PLAINTEXT"); query.Set("oauth_timestamp", "" + (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); query.Set("oauth_nonce", "" + getNonce()); query.Set("oauth_version", "1.0"); builder.Query = query.ToString(); return builder.Uri; } </code></pre> <p>Sometimes, the oauth_signature parameter contains an ampersand although this should be properly encoded with %26 by the NameValueCollection object, and, as result, I get a "401 Unauthorized". I have the feeling this happens when the method is being accessed by multiple background workers (multiple threads?). Is that possible?</p> <p><strong>Edit 2:</strong> Okay, it seems that I've narrowed down the issue. If I do a <code>Debug.Assert(builder.Uri.ToString().Contain("%26") &amp;&amp; builder.Uri.PathAndQuery.Contains("%26"));</code> it turns out that <code>builder.Uri.ToString()</code> does not contain the %26 while <code>builder.Uri.PathAndQuery</code> does. Now, why's that?</p> <p>Debugging the issue turned out to be very hard. Does anyone have any suggestions?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload