private void BuildParamList() { PostItems.Clear(); PostItems.Add("merchant", MerchantID); PostItems.Add("trans_id", _transID); PostItems.Add("amount", _amount); PostItems.Add("callback", UrlSuccess); PostItems.Add("digest", _digest); PostItems.Add("currency", Currency); }
/// <summary> /// Posts the supplied data to specified url. /// </summary> /// <returns>a string containing the result of the post.</returns> public PostResult Post() { StringBuilder parameters = new StringBuilder(); for (int i = 0; i < PostItems.Count; i++) { EncodeAndAddItem(ref parameters, PostItems.GetKey(i), PostItems[i]); } return(PostData(Url, parameters.ToString())); }
public string GetURL() { StringBuilder parameters = new StringBuilder(); for (int i = 0; i < PostItems.Count; i++) { EncodeAndAddItem(ref parameters, PostItems.GetKey(i), PostItems[i]); } string result = Url + "?" + parameters.ToString(); return(result); }
/// <summary> /// Posts the supplied data to specified url. /// </summary> /// <returns>a string containing the result of the post.</returns> public string Post(string url) { StringBuilder parameters = new StringBuilder(); for (int i = 0; i < PostItems.Count; i++) { EncodeAndAddItem(ref parameters, PostItems.GetKey(i), PostItems[i]); } string result = PostData(url, parameters.ToString()); return(result); }
/// <summary> /// /// </summary> /// <param name="uri"></param> /// <param name="s3Bucket"></param> /// <param name="formData"></param> /// <param name="mediaType">text/plain, application/json</param> /// <param name="compressedFile"></param> /// <returns></returns> public static string PostFile(string host, string uri, PostItems items, int Timeout = 10000) { var client = new RestClient(host); RestRequest request = new RestRequest(uri, Method.POST); //request.AddHeader("FileName", "mytest.txt"); request.AddHeader("Content-Type", "multipart/form-data"); foreach (PostItem item in items) { if (item is PostItem_String) { request.AddParameter(item.Name, (item as PostItem_String).Value); } else if (item is PostItem_File) { request.AddFile(item.Name, (item as PostItem_File).Value); } } request.ReadWriteTimeout = Timeout; request.Timeout = Timeout; return(client.Execute(request).Content); //using (var client = new HttpClient()) //{ // MultipartFormDataContent content = new MultipartFormDataContent(); // foreach (KeyValuePair<string, object> item in Contents) // { // if (item.Value is string) // { // content.Add(new StringContent(item.Value.ToString()), item.Key); // } // else if (item.Value is byte[]) // { // content.Add(new ByteArrayContent((byte[])item.Value), item.Key); // } // else if (item.Value is System.IO.FileStream) // { // using (System.IO.FileStream stream = (System.IO.FileStream)item.Value) // { // ByteArrayContent file_content = new ByteArrayContent(new StreamContent(stream).ReadAsByteArrayAsync().Result); // file_content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data"); // content.Add(file_content, "file"); // //file_content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); // //file_content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") // //file_content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") // //{ // // FileName = "screenshot.png", // // Name = "foo", // //}; // } // } // } // HttpResponseMessage response = client.PostAsync(uri, content).Result; // return response.Content.ReadAsStringAsync().Result; // //HttpResponseMessage response = await client.PostAsync(uri, content); // //response.EnsureSuccessStatusCode(); //} //HttpResponseMessage response; //using (var client = new HttpClient()) //{ // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/bson")); // var requestContent = new MultipartFormDataContent(); // foreach (KeyValuePair<string, object> item in Contents) // { // if (item.Value is string) // { // requestContent.Add(new StringContent(item.Value.ToString()), item.Key); // } // else if (item.Value is byte[]) // { // requestContent.Add(new ByteArrayContent((byte[])item.Value), item.Key); // } // else if (item.Value is System.IO.Stream) // { // requestContent.Add(new StreamContent((System.IO.Stream)item.Value), item.Key); // } // } // response = client.PostAsync(uri, requestContent).Result; // return response.Content.ReadAsStringAsync().Result; //} }
private void InitializeForPost() { postItems = helper.GetItemsForPost(); UpdateForm(postItems); }
private void UpdateForm(PostItems itemsForPost) { var normalizedBase64Img = itemsForPost.Base64Image.Replace("data:image/png;base64,", string.Empty); captchaPictureBox.Image = Helpers.Base64StringToBitmap(normalizedBase64Img); }
/// <summary> /// 上传图片到图床地址中 /// </summary> /// <param name="content"></param> /// <param name="input"></param> /// <param name="postConfig"></param> /// <returns></returns> private async Task <string> UploadpicturesToPictureBedAsync(string content, GitlabPostsNavInput input, PostItems postConfig) { if (content == null) { return(null); } //获取上传图片列表 var toDoImgBedList = Regex.Matches(content, @"(<img\s+[^>]*)src=""([^""]*)""([^>]*>)", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline); var newSourceImagesList = new List <string>(); foreach (Match itemPic in toDoImgBedList) { //检查是否为外联,如果是外联按不处理 if (WebUrlHelper.IsExternalLink(itemPic.Groups[2].Value)) { newSourceImagesList.Add(itemPic.Groups[2].Value); //检查图片是否为外部链接 } else { input.FileName = itemPic.Groups[2].Value; var file = await _gitlabClientAppService.GetGitlabFileInfo(input); if (file == null) { continue; } //获取当前图片的base64,然后上传到图床中。 var tags = postConfig.tags.Split(','); var directoryPath = $"{postConfig.blogShortName}/{tags[0]}"; //存放的图床仓库和地址 var pictureToBed = new UploadPictureToBed { PathWithNamespace = "52abp/picturebed", file = file, DirectoryPath = directoryPath }; //上传图片到指定图床 var imgRawUrl = await _gitlabClientAppService.UploadPictureToImgBed(pictureToBed); newSourceImagesList.Add(imgRawUrl); //install-ubuntu-1.png //http://code.52abp.com/52abp/picturebed/raw/master/2020/04/28/install-ubuntu-1.png } } //将本地图源,替换为远程图床的图源 content = Regex.Replace(content, @"(<img\s+[^>]*)src=""([^""]*)""([^>]*>)", (Match match) => { var oldImageSource = match.Groups[2].Value; if (WebUrlHelper.IsExternalLink(oldImageSource)) { //检查图片是否为外部链接 var newurl = match.Groups[1] + " class=\"img-fluid\" src =\"" + oldImageSource + "\" " + match.Groups[3]; return(newurl); // return match.Value; } oldImageSource = Path.GetFileName(oldImageSource); var newImageSource = newSourceImagesList .FirstOrDefault(a => a.EndsWith(oldImageSource)); var url = match.Groups[1] + " class=\"img-fluid\" src =\"" + newImageSource + "\" " + match.Groups[3]; return(url); }, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline); return(content); }