1

I'm attempting to make a web request through a WebClient in a Windows Phone 8.1 Application. The web request contains a set of search terms, which whilst building the request signature are percent encoded as such: OAuthTools.UrlEncodeStrict(searchTerms), this is done because the search terms likely contain spaces. I then add all other parameters, and generate a signature. The request URL will then look something like this:

http://platform.fatsecret.com/rest/server.api?format=json&max_results=10&method=recipes.search&oauth_consumer_key=******&oauth_nonce=ksoordxpd5oahp9e&oauth_signature=Uxq3pmkTkRrASO%2Bmoiujs24BtT4%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1420634671&oauth_version=1.0&page_number=0&search_expression=pumpkin%20pie

As you can see, the final parameter, search_expression=pumpkin%20pie is encoded correctly. However, when putting this URL into a URI object (as the WebClient.DownloadStringAsync method requires), the URL is decoded to:

http://platform.fatsecret.com/rest/server.api?format=json&max_results=10&method=recipes.search&oauth_consumer_key=******&oauth_nonce=ksoordxpd5oahp9e&oauth_signature=Uxq3pmkTkRrASO%2Bmoiujs24BtT4%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1420634671&oauth_version=1.0&page_number=0&search_expression=pumpkin pie

Removing the escaped spacing for the search_expression parameter. This results, in this case, in an invalid OAuth signature (as the parameters change), but using an unescaped search_expression with spaces also results in an invalid OAuth signature (I assume because REST parameters should not contain spaces). Is there a way to ensure that the URI class does not decode my URL string? I have found this answer explaining that a workaround is to include:

<uri>
  <schemeSettings>
    <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
  </schemeSettings>
</uri>

Inside of the Web.config or App.config file. However, there appears to be no suitable config file to place this in inside a Windows Phone 8.1 development environment (I have tried adding it to packages.config and the app manifest, neither of which had any effect). Is there another way around this issue? Or alternatively, is there another way I can send a web request using a raw string, as opposed to through a URI object?

Community
  • 1
  • 1
FinalFanatic
  • 383
  • 2
  • 4
  • 13
  • This looks like a nice solution http://stackoverflow.com/questions/13759034/uri-constructor-with-dontescape-is-obsolete-what-is-alternatieve – Moti Azu Jan 07 '15 at 13:02
  • How do you know it's being incorrectly encoded? When you create your `Uri`, what does `uri.AbsoluteUri` give you? – spender Jan 07 '15 at 13:05
  • Hmm, ok, so the problem appears to be elsewhere. The absolute URI is correct, however I still get an invalid OAuth signature error (this works fine for searches with no spaces in). – FinalFanatic Jan 07 '15 at 13:12
  • @user3750097 Are you sure you should be signing the escaped representation? – spender Jan 07 '15 at 13:19
  • @spender As far as I know, yes. The [API documentation](http://platform.fatsecret.com/api/Default.aspx?screen=rapiauth#create_signature_base) states to encode the signature base , and it works perfectly for a single search term. I'll try without escaping the search expression, just to check. – FinalFanatic Jan 07 '15 at 13:27

0 Answers0