public WebResponse Request(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken, WebHeaderCollection requestHeaders, byte[] requestBody, bool rawBody, CookieCollection cookieCollection, bool isPhoto) { var signer = new OAuthSigner(); var additionalParameters = new NameValueCollection(); WebRequest request = null; request = WebRequest.Create(this.ApiServerUri + resourcePath); if (httpMethod != HttpMethodType.GET) { if (rawBody) { if (isPhoto) request.ContentType = "image/jpg"; else request.ContentType = "video/mpeg"; // f0r AVI video } else { if (this.Scheme == AuthorizationSchemeType.Body) { request.ContentType = "application/" + OAuthConstants.X_WWW_FORM_URLENCODED; } else { request.ContentType = "application/" + OAuthConstants.X_WWW_FORM_URLENCODED; } if (requestBody != null && requestBody.Length > 0) { additionalParameters = HttpUtility.ParseQueryString(Encoding.UTF8.GetString(requestBody)); } } } request.Method = httpMethod.ToString(); string oAuthQuerystring = null; request = signer.SignRequest(request, this, consumerToken, additionalParameters,out oAuthQuerystring); ((HttpWebRequest)request).Accept = "*/*"; if (httpMethod == HttpMethodType.POST && !isPhoto && !string.IsNullOrEmpty(oAuthQuerystring)) { requestBody = Encoding.ASCII.GetBytes(oAuthQuerystring); } return RawRequest(request, requestHeaders, requestBody, cookieCollection); }
public OAuthToken TokenRequest(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken, WebHeaderCollection requestHeaders) { var response = (HttpWebResponse)this.Request(httpMethod, resourcePath, consumerToken, requestHeaders, null, null); var streamReader = new StreamReader(response.GetResponseStream()); var responseBody = streamReader.ReadToEnd(); switch (response.StatusCode) { case HttpStatusCode.OK: return ParseTokenResponse(responseBody); default: throw new Exception(string.Format("{0} - {1}", response.StatusCode, responseBody)); } }
public WebResponse Request(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken, WebHeaderCollection requestHeaders, byte[] requestBody, bool rawBody, CookieCollection cookieCollection) { return Request(httpMethod, resourcePath, consumerToken, requestHeaders, requestBody, false, cookieCollection, false); }
public WebResponse Request(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken, WebHeaderCollection requestHeaders, byte[] requestBody) { return Request(httpMethod, resourcePath, consumerToken, requestHeaders, requestBody, null); }
public WebResponse Request(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken) { return Request(httpMethod, resourcePath, consumerToken, null, null, null); }
public WebResponse RawRequest(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken, WebHeaderCollection requestHeaders, byte[] requestBody) { if (string.IsNullOrEmpty(resourcePath)) { throw new ArgumentNullException("resourcePath"); } var request = (HttpWebRequest)WebRequest.Create(this.ApiServerUri + resourcePath); request.Method = httpMethod.ToString(); return RawRequest(request, requestHeaders, requestBody); }
public WebResponse RawRequest(HttpMethodType httpMethod, string resourcePath, ConsumerToken consumerToken, WebHeaderCollection requestHeaders) { return this.RawRequest(httpMethod, resourcePath, consumerToken, requestHeaders, null); }