当前位置: 首页>>代码示例>>C#>>正文


C# RestRequest.AddFile方法代码示例

本文整理汇总了C#中RestSharp.Portable.RestRequest.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddFile方法的具体用法?C# RestRequest.AddFile怎么用?C# RestRequest.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestSharp.Portable.RestRequest的用法示例。


在下文中一共展示了RestRequest.AddFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Upload

        public async Task<UploadStatus> Upload(ActivityType activityType, DataType dataType, System.IO.Stream input, string fileName, string name = null, string description = null,
            bool @private = false, bool commute = false)
        {
            var request = new RestRequest("/api/v3/uploads?data_type={data_type}&activity_type={activity_type}&private={private}&commute={commute}", Method.POST);
            if (name != null)
            {
                request.Resource += "&name={name}";
                request.AddParameter("name", name, ParameterType.UrlSegment);
            }
            if (description != null)
            {
                request.Resource += "&description={description}";
                request.AddParameter("description", description, ParameterType.UrlSegment);
            }

            request.ContentCollectionMode = ContentCollectionMode.MultiPart;
            request.AddParameter("data_type", dataType, ParameterType.UrlSegment);
            request.AddParameter("activity_type", EnumHelper.ToString(activityType), ParameterType.UrlSegment);
            request.AddParameter("private", @private ? 1 : 0, ParameterType.UrlSegment);
            request.AddParameter("commute", commute ? 1 : 0, ParameterType.UrlSegment);
            request.AddFile("file", input, Uri.EscapeDataString(fileName));
            var response = await _client.RestClient.Execute<UploadStatus>(request);
            return response.Data;
        }
开发者ID:gabornemeth,项目名称:StravaSharp,代码行数:24,代码来源:ActivityClient.cs

示例2: CreateUploadFileRequest

        public RestRequest CreateUploadFileRequest(string path, string filename, Stream fileStream, string root, bool overwrite, string parent_revision)
        {
            var request = new RestRequest("{version}/files/{root}{path}", HttpMethod.Post);
            request.AddParameter("version", _version, ParameterType.UrlSegment);
            request.AddParameter("path", path, ParameterType.UrlSegment);
            request.AddParameter("root", root, ParameterType.UrlSegment);
            //Need to add the "file" parameter with the file name
            // This isn't needed. Dropbox is particular about the ordering,
            // but the oauth sig only needs the filename, which we have in the OTHER parameter
            //request.AddParameter("file", filename);

            request.AddParameter("overwrite", overwrite);
            if (!String.IsNullOrEmpty(parent_revision))
            {
                request.AddParameter("parent_rev", parent_revision);
            }

            request.AddFile("file", fileStream, filename);

            return request;
        }
开发者ID:gabornemeth,项目名称:DropNet,代码行数:21,代码来源:RequestHelper.cs

示例3: AddImageAsync

        /// <summary>
        /// Posts an image to the api.
        /// </summary>
        /// <returns></returns>
        private async Task<int?> AddImageAsync()
        {
            using (var client = new RestClient("http://localhost:55298/api/"))
            {
                var request = new RestRequest("images", Method.POST);
                var data = await ReadFileAsync(this.imageFile);
                request.AddFile(FileParameter.Create("file", data, this.imageFile.Name));

                try
                {
                    var image = await client.Execute<Image>(request);
                    return image.Data.Id;
                }
                catch
                {
                    return null;
                }
            }
        }
开发者ID:danielbeckmann,项目名称:DotNETJumpStart,代码行数:23,代码来源:AddPostViewModel.cs

示例4: SendApplicationAsync

        /// <summary>
        /// Antrag versenden
        /// </summary>
        /// <param name="application">Antrag</param>
        /// <param name="p10Data">PKCS#10-Daten</param>
        /// <param name="certStore">Zertifikat-Speicher für die Bildung der Zertifikatskette und die Abfrage des Empfänger-Zertifikats</param>
        /// <param name="pfx">Zertifikat für die Verschlüsselung - wenn nicht gesetzt, dann wird ein Erstantrag erstellt</param>
        /// <param name="validator">The validator for the OSTC certificate request document</param>
        /// <returns>Das Ergebnis der Antragstellung</returns>
        public async Task<OstcApplicationResult> SendApplicationAsync([NotNull] OstcAntrag application, [NotNull] Pkcs10Data p10Data, [CanBeNull] IOstcCertificateStore certStore, [CanBeNull] Pkcs12Store pfx, [CanBeNull] IValidator validator)
        {
            var senderId = SenderId.FromBnrOrIk(application.Antragsteller.IK_BN);

            var applicationData = OstcUtils.Serialize(application, Iso88591);
            string mimeType;
            if (pfx == null)
            {
                mimeType = "text/xml";
            }
            else
            {
                var alias = pfx.Aliases.Cast<string>().FirstOrDefault(pfx.IsKeyEntry);
                if (alias != null)
                {
                    var certEntry = pfx.GetCertificate(alias);
                    var keyEntry = pfx.GetKey(alias);
                    var certificate = certEntry.Certificate;
                    var key = keyEntry.Key;
                    if (certStore == null)
                        throw new ArgumentNullException(nameof(certStore));
                    var certChain = certStore.GetChain(certificate).ToList();
                    System.Diagnostics.Debug.Assert(certChain[0].SubjectDN.Equivalent(certificate.SubjectDN));
                    certChain.RemoveAt(0);
                    applicationData = OstcUtils.SignData(applicationData, key, certificate, certChain);
                    var receiverCert = certStore.GetCertificate(senderId.CommunicationServerReceiver);
                    applicationData = OstcUtils.EncryptData(applicationData, receiverCert);
                    mimeType = "application/octet-stream";
                }
                else
                {
                    mimeType = "text/xml";
                }
            }

            var date = DateTime.ParseExact(application.Antragsinfo.Datum, "dd.MM.yyyy", CultureDe);
            var p10FileName = $"{senderId.Id}.p10";
            var xmlFileName = $"{senderId}_{date:ddMMyyyy}.xml";

            var requestSendApp = new RestRequest(Network.Requests.Upload);
            requestSendApp.AddParameter("MAX_FILE_SIZE_XML", "4000");
            requestSendApp.AddFile("xml_Datei", applicationData, xmlFileName, mimeType);
            requestSendApp.AddParameter("MAX_FILE_SIZE_P10", "4000");
            requestSendApp.AddFile("p10_Datei", p10Data.CertRequestDer, p10FileName);

            var responseSendApp = await Client.Execute(requestSendApp);
            var responseHtml = DecodeResponse(new MemoryStream(responseSendApp.RawBytes));
            var responseFileUrl = GetResponseFileUrl(responseHtml);
            if (responseFileUrl == null)
                throw new OstcException("Von der ITSG wurde kein Pfad zu einer Rückmeldungs-Datei geliefert.");

            var downloadRequest = new RestRequest(responseFileUrl, Method.GET);
            var downloadResponse = await Client.Execute(downloadRequest);
            var resultData = downloadResponse.RawBytes;

            var resultXml = XDocument.Load(new MemoryStream(resultData));

            var trustCenterNode = resultXml
                .Elements("OSTCAntrag")
                .Elements("Trustcenter")
                .FirstOrDefault();
            if (trustCenterNode == null)
                throw new InvalidOperationException("Die von der ITSG zurückgelieferte Antwort lag in einem unbekannten Format vor.");
            var returnCodeNode = trustCenterNode
                .Elements("Returncode")
                .FirstOrDefault();
            if (returnCodeNode == null)
                throw new InvalidOperationException("Die von der ITSG zurückgelieferte Antwort lag in einem unbekannten Format vor.");
            var returnCode = Convert.ToInt32(returnCodeNode.Value.Trim(), 10);
            var errorCodeNode = trustCenterNode.Elements("Fehlercode").FirstOrDefault();
            if (errorCodeNode == null)
                throw new InvalidOperationException("Die von der ITSG zurückgelieferte Antwort lag in einem unbekannten Format vor.");
            var errorCodes = errorCodeNode.Value.Trim()
                .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => Convert.ToInt32(x.Trim(), 10))
                .ToList();

            var inputNumberNode = trustCenterNode.Elements("Eingangsnummer").FirstOrDefault();
            if (inputNumberNode == null)
                throw new InvalidOperationException("Die von der ITSG zurückgelieferte Antwort lag in einem unbekannten Format vor.");
            var inputNumber = inputNumberNode.Value.Trim();
            var result = new OstcApplicationResult()
            {
                OrderId = inputNumber,
                ReturnCode = returnCode,
                ErrorCodes = errorCodes,
            };

            return result;
        }
开发者ID:dataline-gmbh,项目名称:Itsg.Ostc,代码行数:99,代码来源:OstcClient.cs


注:本文中的RestSharp.Portable.RestRequest.AddFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。