protected string SignedPost (string url, IDictionary<string,string> parameters, OAuth.Token token) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Headers.Add ("Authorization", OAuth.Sign (Consumer, url, parameters, token, "POST", null)); StreamWriter streamWriter = new StreamWriter (request.GetRequestStream ()); streamWriter.Write (OAuth.PercentEscape (parameters)); streamWriter.Close (); HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse (); } catch(WebException e) { RdioException re; response = (HttpWebResponse)e.Response; if (response.StatusCode == HttpStatusCode.Forbidden || response.StatusCode == HttpStatusCode.Unauthorized) { re = new AuthorizationException(); } else { re = new RdioException(); } re.Request = request; re.Response = response; re.Exception = e; throw re; } StreamReader streamReader = new StreamReader (response.GetResponseStream ()); return streamReader.ReadToEnd (); }
protected string SignedPost(string url, IDictionary <string, string> parameters, OAuth.Token token) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Headers.Add("Authorization", OAuth.Sign(Consumer, url, parameters, token, "POST", null)); StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()); streamWriter.Write(OAuth.PercentEscape(parameters)); streamWriter.Close(); HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException e) { RdioException re; response = (HttpWebResponse)e.Response; if (response.StatusCode == HttpStatusCode.Forbidden || response.StatusCode == HttpStatusCode.Unauthorized) { re = new AuthorizationException(); } else { re = new RdioException(); } re.Request = request; re.Response = response; re.Exception = e; throw re; } StreamReader streamReader = new StreamReader(response.GetResponseStream()); return(streamReader.ReadToEnd()); }