コード例 #1
0
        public string GetAuthorizationURL()
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("response_type", "code");
            args.Add("redirect_uri", Links.URL_CALLBACK);
            args.Add("scope", "openid teknik-api.write offline_access");
            args.Add("client_id", AuthInfo.Client_ID);

            return(URLHelpers.CreateQueryString(AuthUrl + "/connect/authorize", args));
        }
コード例 #2
0
ファイル: Uploader.cs プロジェクト: alshain/ShareX
        protected HttpWebResponse GetResponse(HttpMethod method, string url, Stream data = null, string contentType = null, Dictionary <string, string> args = null,
                                              NameValueCollection headers = null, CookieCollection cookies          = null, bool allowNon2xxResponses = false)
        {
            IsUploading         = true;
            StopUploadRequested = false;

            try
            {
                url = URLHelpers.CreateQueryString(url, args);

                long contentLength = 0;

                if (data != null)
                {
                    contentLength = data.Length;
                }

                HttpWebRequest request = CreateWebRequest(method, url, headers, cookies, contentType, contentLength);

                if (contentLength > 0)
                {
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        if (!TransferData(data, requestStream))
                        {
                            return(null);
                        }
                    }
                }

                return((HttpWebResponse)request.GetResponse());
            }
            catch (WebException we) when(we.Response != null && allowNon2xxResponses)
            {
                // if we.Response != null, then the request was successful, but
                // returned a non-200 status code
                return(we.Response as HttpWebResponse);
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    AddWebError(e, url);
                }
            }
            finally
            {
                currentWebRequest = null;
                IsUploading       = false;
            }

            return(null);
        }
コード例 #3
0
        public string GetAuthorizationURL()
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("client_id", AuthInfo.Client_ID);
            args.Add("scope", "all");
            args.Add("state", "ShareX");
            args.Add("response_type", "code");
            args.Add("redirect_uri", Links.URL_CALLBACK);

            return(URLHelpers.CreateQueryString(URL_AUTHORIZE, args));
        }
コード例 #4
0
ファイル: OneDrive.cs プロジェクト: ywscr/ShareX
        public string GetAuthorizationURL()
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("client_id", AuthInfo.Client_ID);
            args.Add("scope", "offline_access files.readwrite");
            args.Add("response_type", "code");
            args.Add("redirect_uri", Links.URL_CALLBACK);
            if (AuthInfo.Proof != null)
            {
                args.Add("code_challenge", AuthInfo.Proof.CodeChallenge);
                args.Add("code_challenge_method", AuthInfo.Proof.ChallengeMethod);
            }

            return(URLHelpers.CreateQueryString(AuthorizationEndpoint, args));
        }
コード例 #5
0
ファイル: MediaFire.cs プロジェクト: McoreD/ShareX
        private string SimpleUpload(Stream stream, string fileName)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("session_token", sessionToken);
            args.Add("path", UploadPath);
            args.Add("response_format", "json");
            args.Add("signature", GetSignature("upload/simple.php", args));
            string       url = URLHelpers.CreateQueryString(apiUrl + "upload/simple.php", args);
            UploadResult res = SendRequestFile(url, stream, fileName, "Filedata");

            if (!res.IsSuccess)
            {
                throw new IOException(res.ErrorsToString());
            }
            SimpleUploadResponse resp = DeserializeResponse <SimpleUploadResponse>(res.Response);

            EnsureSuccess(resp);
            if (resp.doupload.result != 0 || resp.doupload.key == null)
            {
                throw new IOException("Invalid response");
            }
            return(resp.doupload.key);
        }
コード例 #6
0
ファイル: Uploader.cs プロジェクト: alshain/ShareX
        protected UploadResult SendRequestFileRange(string url, Stream data, string fileName, long contentPosition = 0, long contentLength = -1,
                                                    Dictionary <string, string> args = null, NameValueCollection headers = null, CookieCollection cookies = null, HttpMethod method = HttpMethod.PUT)
        {
            UploadResult result = new UploadResult();

            IsUploading         = true;
            StopUploadRequested = false;

            try
            {
                url = URLHelpers.CreateQueryString(url, args);

                if (contentLength == -1)
                {
                    contentLength = data.Length;
                }
                contentLength = Math.Min(contentLength, data.Length - contentPosition);

                string contentType = UploadHelpers.GetMimeType(fileName);

                if (headers == null)
                {
                    headers = new NameValueCollection();
                }
                long startByte  = contentPosition;
                long endByte    = startByte + contentLength - 1;
                long dataLength = data.Length;
                headers.Add("Content-Range", $"bytes {startByte}-{endByte}/{dataLength}");

                HttpWebRequest request = CreateWebRequest(method, url, headers, cookies, contentType, contentLength);

                using (Stream requestStream = request.GetRequestStream())
                {
                    if (!TransferData(data, requestStream, contentPosition, contentLength))
                    {
                        return(null);
                    }
                }

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    result.Response = ProcessWebResponse(response);
                }

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    string response = AddWebError(e, url);

                    if (ReturnResponseOnError && e is WebException)
                    {
                        result.Response = response;
                    }
                }
            }
            finally
            {
                currentWebRequest = null;
                IsUploading       = false;

                if (VerboseLogs && !string.IsNullOrEmpty(VerboseLogsPath))
                {
                    WriteVerboseLog(url, args, headers, result.Response);
                }
            }

            return(result);
        }
コード例 #7
0
ファイル: Uploader.cs プロジェクト: alshain/ShareX
        internal string SendRequestURLEncoded(HttpMethod method, string url, Dictionary <string, string> args, NameValueCollection headers = null, CookieCollection cookies = null)
        {
            string query = URLHelpers.CreateQueryString(args);

            return(SendRequest(method, url, query, UploadHelpers.ContentTypeURLEncoded, null, headers, cookies));
        }