Exemplo n.º 1
0
        void OrnekCalismaTestDummy()
        {
            var icon = BitmapFactory.DecodeResource(Resources, Resource.Mipmap.aaestro);
            var ms   = new MemoryStream();

            icon.Compress(Bitmap.CompressFormat.Png, 0, ms);
            byte[] mediabyte = ms.ToArray();

            var MeID = DataBase.MEMBER_DATA_GETIR()[0];

            var client = new RestSharp.RestClient("http://31.169.67.210:8080/api/examples");

            client.Timeout = -1;
            var request = new RestSharp.RestRequest(RestSharp.Method.POST);

            // request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
            request.AddHeader("Accept", "*/*");
            //request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("Authorization", "Bearer " + MeID.API_TOKEN);
            request.AddParameter("text", "ddddddddd");
            request.AddFile("afterImagePath", mediabyte, "sosi_media_file.png");
            request.AddFile("beforeImagePath", mediabyte, "sosi_media_file1.png");
            RestSharp.IRestResponse response = client.Execute(request);
            if (response.StatusCode != HttpStatusCode.Unauthorized &&
                response.StatusCode != HttpStatusCode.InternalServerError &&
                response.StatusCode != HttpStatusCode.BadRequest &&
                response.StatusCode != HttpStatusCode.Forbidden &&
                response.StatusCode != HttpStatusCode.MethodNotAllowed &&
                response.StatusCode != HttpStatusCode.NotAcceptable &&
                response.StatusCode != HttpStatusCode.RequestTimeout &&
                response.StatusCode != HttpStatusCode.NotFound)
            {
                var jsonobj = response.Content;
                //var Icerik = Newtonsoft.Json.JsonConvert.DeserializeObject<MediaUploadDTO>(jsonobj.ToString());
                //if (Icerik != null)
                //{
                //    return Icerik.beforeMediaPath;
                //}
                //else
                //{
                //    return "";
                //}
            }
            else
            {
                //return "";
            }
        }
        private string Upload(byte[] bytes, string fileName)
        {
            var campaignApiUrl   = _siteSettingsService.GetSettingsOrDefault().CampaignApiUrl;
            var campaignAuthCode = _siteSettingsService.GetSettingsOrDefault().CampaignTransactionalAuthorizationCode;

            if (string.IsNullOrEmpty(campaignApiUrl) || string.IsNullOrEmpty(campaignAuthCode))
            {
                Log.Error($"Error uploading file to Campaign. Campaign settings are missing.");
                return(null);
            }

            //using RestSharp for the assistance with the image post
            var restClient = new RestSharp.RestClient(campaignApiUrl.Trim('/'));
            var request    = new RestSharp.RestRequest($"{campaignAuthCode.Trim()}/uploadpersonalizedattachments", RestSharp.Method.POST)
            {
                AlwaysMultipartFormData = true
            };

            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddFile(MessageArgument.AttachmentFile.Value, bytes, fileName, System.Web.MimeMapping.GetMimeMapping(fileName));
            var restResponse = restClient.Execute(request);

            if (!restResponse.Content.ToLower().StartsWith("ok"))
            {
                Log.Error($"Error uploading attachment to Campaign. Campaign message: {restResponse.Content}. Filename: {fileName}");
                return(string.Empty);
            }

            return(restResponse.Content.Replace("ok:", "").Trim()); //return the attachment token value wich will be sent with a message as an additional argument
        }
Exemplo n.º 3
0
        /// <summary>
        /// Uploads the binary file returning the resulting binaryFile.Id
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileTypeGuid">The file type unique identifier.</param>
        /// <param name="fileData">The file data.</param>
        /// <param name="isTemporary">if set to <c>true</c> [is temporary].</param>
        /// <returns></returns>
        public int UploadBinaryFile(string fileName, Guid fileTypeGuid, byte[] fileData, bool isTemporary)
        {
            RestSharp.RestClient restClient = new RestSharp.RestClient(this.rockBaseUri);
            restClient.CookieContainer = this.CookieContainer;
            RestSharp.RestRequest request = new RestSharp.RestRequest("FileUploader.ashx", RestSharp.Method.POST);
            request.AddQueryParameter("isBinaryFile", "true");
            request.AddQueryParameter("fileTypeGuid", fileTypeGuid.ToString());
            request.AddQueryParameter("isTemporary", isTemporary.ToString());
            request.AddFile("file0", fileData, fileName);
            var response = restClient.Execute(request).Content;

            dynamic responseObj = JsonConvert.DeserializeObject(response);

            return(responseObj.Id);
        }
Exemplo n.º 4
0
        void UploadWebService(MediaUploadDTO MediaUploadDTO1, byte[] mediabyte, YUKLENECEK_SABLON GuncellenecekSablon, int count)
        {
            string jsonString = JsonConvert.SerializeObject(MediaUploadDTO1);
            string uzanti     = ".png";

            if (MediaUploadDTO1.video)
            {
                uzanti = ".mp4";
            }
            var client = new RestSharp.RestClient("http://31.169.67.210:8080/api/template-medias");

            client.Timeout = -1;
            var request = new RestSharp.RestRequest(RestSharp.Method.POST);

            //request.Accept = "*/*";
            //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
            //client.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
            request.AddHeader("Accept", "*/*");
            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("Authorization", "Bearer " + MeId.API_TOKEN);
            request.AddParameter("mediaCount", MediaUploadDTO1.mediaCount);
            request.AddParameter("postText", MediaUploadDTO1.postText);
            request.AddParameter("templateId", MediaUploadDTO1.templateId);
            request.AddParameter("video", MediaUploadDTO1.video);
            request.AddParameter("userId", MeId.id);
            request.AddParameter("processed", false);
            request.AddParameter("type", "POST");
            request.AddFile("photo", mediabyte, "sosi_media_file" + uzanti);
            RestSharp.IRestResponse response = client.Execute(request);
            if (response.StatusCode != HttpStatusCode.Unauthorized &&
                response.StatusCode != HttpStatusCode.InternalServerError &&
                response.StatusCode != HttpStatusCode.BadRequest &&
                response.StatusCode != HttpStatusCode.Forbidden &&
                response.StatusCode != HttpStatusCode.MethodNotAllowed &&
                response.StatusCode != HttpStatusCode.NotAcceptable &&
                response.StatusCode != HttpStatusCode.RequestTimeout &&
                response.StatusCode != HttpStatusCode.NotFound)
            {
                GuncellenecekSablon.isUploaded = true;
                DataBase.YUKLENECEK_SABLON_Guncelle(GuncellenecekSablon);
                GleenBase2.RunOnUiThread(delegate()
                {
                    MedyaUploadServiceDialogFragment1.UploadProgress(count + 1);
                });
            }
        }
Exemplo n.º 5
0
        string OnceLogoyuYule()
        {
            var MeID   = DataBase.MEMBER_DATA_GETIR()[0];
            var client = new RestSharp.RestClient("http://31.169.67.210:8080/api/template-medias");

            client.Timeout = -1;
            byte[] mediabyte = ConvertImageToByte(((LogoFragment)fragments[3]).GetCompanyLogoPath());
            var    request   = new RestSharp.RestRequest(RestSharp.Method.POST);

            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
            request.AddHeader("Accept", "*/*");
            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("Authorization", "Bearer " + MeID.API_TOKEN);
            request.AddParameter("mediaCount", 0);
            request.AddParameter("postText", "");
            request.AddParameter("templateId", "0");
            request.AddParameter("video", false);
            request.AddParameter("userId", MeID.id);
            request.AddParameter("processed", false);
            request.AddParameter("type", "POST");
            request.AddFile("photo", mediabyte, "sosi_media_file.png");
            RestSharp.IRestResponse response = client.Execute(request);
            if (response.StatusCode != HttpStatusCode.Unauthorized &&
                response.StatusCode != HttpStatusCode.InternalServerError &&
                response.StatusCode != HttpStatusCode.BadRequest &&
                response.StatusCode != HttpStatusCode.Forbidden &&
                response.StatusCode != HttpStatusCode.MethodNotAllowed &&
                response.StatusCode != HttpStatusCode.NotAcceptable &&
                response.StatusCode != HttpStatusCode.RequestTimeout &&
                response.StatusCode != HttpStatusCode.NotFound)
            {
                var jsonobj = response.Content;
                var Icerik  = Newtonsoft.Json.JsonConvert.DeserializeObject <MediaUploadDTO>(jsonobj.ToString());
                if (Icerik != null)
                {
                    return(Icerik.beforeMediaPath);
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 上传单个文件
        /// </summary>
        /// <param name="url"></param>
        /// <param name="uploadFile"></param>
        /// <returns></returns>
        public static string Post(string url, UploadFile uploadFile)
        {
            logger.Debug($"[Post]请求:{url}");
            var client = new RestSharp.RestClient(url);
            var req    = new RestSharp.RestRequest();

            req.Method = RestSharp.Method.POST;
            req.AddFile(uploadFile.Name, uploadFile.Data, uploadFile.Filename, uploadFile.ContentType);
            var resp = client.Execute(req);

            if (!resp.IsSuccessful)
            {
                logger.Error("上传文件失败");
                throw new SpException("上传文件失败:" + resp.ErrorException.Message);
            }
            return(resp.Content);
        }
Exemplo n.º 7
0
 void OnceLogoyuYule(byte[] mediabyte)
 {
     ShowLoading.Show(this, "Lütfen Bekleyin...");
     new System.Threading.Thread(new System.Threading.ThreadStart(delegate
     {
         var MeID       = DataBase.MEMBER_DATA_GETIR()[0];
         var client     = new RestSharp.RestClient("http://185.184.210.20:8080/api/users/profile-photos");
         client.Timeout = -1;
         var request    = new RestSharp.RestRequest(RestSharp.Method.POST);
         request.AddHeader("Content-Type", "multipart/form-data");
         request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
         request.AddHeader("Accept", "*/*");
         request.AddHeader("Content-Type", "multipart/form-data");
         request.AddHeader("Authorization", "Bearer " + MeID.API_TOKEN);
         request.AddFile("photo", mediabyte, "testbang_user_img.jpg");
         RestSharp.IRestResponse response = client.Execute(request);
         if (response.StatusCode != HttpStatusCode.Unauthorized &&
             response.StatusCode != HttpStatusCode.InternalServerError &&
             response.StatusCode != HttpStatusCode.BadRequest &&
             response.StatusCode != HttpStatusCode.Forbidden &&
             response.StatusCode != HttpStatusCode.MethodNotAllowed &&
             response.StatusCode != HttpStatusCode.NotAcceptable &&
             response.StatusCode != HttpStatusCode.RequestTimeout &&
             response.StatusCode != HttpStatusCode.NotFound)
         {
             var jsonobj = response.Content;
             if (!string.IsNullOrEmpty(jsonobj))
             {
                 MeID.imageUrl = jsonobj;
                 DataBase.MEMBER_DATA_Guncelle(MeID);
                 AlertHelper.AlertGoster("Profil fotoğrafı güncellendi", this);
             }
             else
             {
                 AlertHelper.AlertGoster("Bir sorun oluştu.", this);
             }
         }
         else
         {
             AlertHelper.AlertGoster("Bir sorun oluştu.", this);
         }
         ShowLoading.Hide();
     })).Start();
 }
Exemplo n.º 8
0
        public static string PostFile(string requestUrl, byte[] filebyte, string filename)
        {
            var restClient = new RestSharp.RestClient();
            var request    = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST);

            request.AddFile("file", filebyte, filename, "application/octet-stream");

            // 追加登录Cookie
            //var cookie = FormsAuthentication.GetAuthCookie(User.Identity.Name, true);
            //request.AddCookie(FormsAuthentication.FormsCookieName, cookie.Value);
            request.Timeout = 60000;
            var response = restClient.Execute(request);

            if (response.ResponseStatus != RestSharp.ResponseStatus.Completed)
            {
                LogWriter.Info(string.Format("StatusCode:{0},ResponseStatus:{1},ErrorMessage:{2},apiBaseUri:{3},requestUrl:{4}",
                                             response.StatusCode, response.ResponseStatus, response.ErrorMessage, "", requestUrl));
            }
            return(response.Content);
        }
Exemplo n.º 9
0
        private static void UploadAppBundle(UploadParameters parameters, string bundleZipPath)
        {
            Console.WriteLine($"Uploading app bundle to {parameters.EndpointUrl}.");

            var client  = new RestSharp.RestClient(parameters.EndpointUrl);
            var request = new RestSharp.RestRequest(RestSharp.Method.POST);

            request.AddHeader("Cache-Control", "no-cache");
            request.AlwaysMultipartFormData = true;
            request.AddFile("file", bundleZipPath);
            foreach (var f in parameters.FormData)
            {
                request.AddParameter(f.Key, f.Value, RestSharp.ParameterType.GetOrPost);
            }
            var response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"There was an error uploading the app bundle: {response.Content}");
            }
            Console.WriteLine("App bundle uploaded succesfully.");
        }
Exemplo n.º 10
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            int    numeroDeCriptografia = 6;
            string textoCriptografado   = "znk znxkk mxkgz boxzaky ul g vxumxgsskx: rgfotkyy, osvgzoktik, gtj nahxoy. rgxxe cgrr";
            string textoDescriptografado;


            char[] Char = textoCriptografado.ToCharArray();
            for (int i = 0; i < Char.Length; i++)
            {
                if ((int)Char[i] > 96 && (int)Char[i] < 123)
                {
                    int value = (int)Char[i] - numeroDeCriptografia;
                    if (value < 97)
                    {
                        value = 123 - (97 - value);
                    }
                    Char[i] = (char)value;
                }
            }
            textoDescriptografado = new string(Char);


            Console.WriteLine(textoDescriptografado);
            Console.WriteLine(Hash(textoDescriptografado));

            var restClient = new RestSharp.RestClient("https://api.codenation.dev");
            var request    = new RestSharp.RestRequest($"/v1/challenge/dev-ps/submit-solution", RestSharp.Method.POST);

            request.AlwaysMultipartFormData = true;
            request.AddHeader("Content-Type", "multipart/form-data");

            request.AddQueryParameter("token", "e2e34c6b93d38dbd1d03d540ba81e7a5dfd3f7c2");

            request.AddFile("answer", "./answer.json");

            var response = restClient.Execute(request);
        }
Exemplo n.º 11
0
        private RestSharp.IRestRequest BuildRestSharpRequest(RestRequest restRequest)
        {
            var restSharpRequest = new RestSharp.RestRequest(restRequest.Resource);

            restSharpRequest.Method        = (RestSharp.Method)Enum.Parse(typeof(RestSharp.Method), restRequest.Method.ToString());
            restSharpRequest.RequestFormat = (RestSharp.DataFormat)Enum.Parse(typeof(RestSharp.DataFormat), restRequest.RequestFormat.ToString());
            restSharpRequest.DateFormat    = restRequest.DateFormat;

            //added by philip to force timeout within 15 seconds for connect
            restSharpRequest.Timeout = 15000;

            //TODO: solve this mapping
            //restSharpRequest.Credentials = restRequest.Credentials;

            if (restRequest.Body != null)
            {
                restSharpRequest.AddBody(restRequest.Body);
            }

            foreach (var item in restRequest.Cookies)
            {
                restSharpRequest.AddCookie(item.Key, item.Value);
            }

            foreach (var item in restRequest.Files)
            {
                if (!string.IsNullOrEmpty(item.Path))
                {
                    restSharpRequest.AddFile(item.Name, item.Path);
                }
                else
                {
                    if (String.IsNullOrEmpty(item.ContentType))
                    {
                        restSharpRequest.AddFile(item.Name, item.Bytes, item.FileName);
                    }
                    else
                    {
                        restSharpRequest.AddFile(item.Name, item.Bytes, item.FileName, item.ContentType);
                    }
                }
            }

            foreach (var item in restRequest.Headers)
            {
                restSharpRequest.AddHeader(item.Key, item.Value);
            }

            foreach (var item in restRequest.UrlSegments)
            {
                restSharpRequest.AddUrlSegment(item.Key, item.Value);
            }

            foreach (var item in restRequest.Objects)
            {
                restSharpRequest.AddObject(item.Key, item.Value);
            }



            foreach (var item in restRequest.Parameters)
            {
                RestSharp.ParameterType t = (RestSharp.ParameterType)Enum.Parse(typeof(RestSharp.ParameterType), item.Type.ToString());

                restSharpRequest.AddParameter(
                    item.Name,
                    item.Value,
                    t
                    );
            }


            return(restSharpRequest);
        }
Exemplo n.º 12
0
        protected RestSharp.IRestResponse PutFile(string url, string path)
        {
            RestSharp.IRestClient client = new RestSharp.RestClient(Root);
            RestSharp.IRestRequest request = new RestSharp.RestRequest(url, RestSharp.Method.PUT);

            request.AddFile("Content", path);

            var response = client.Execute(request);
            return response;
        }