public static string get_9kw_api_upload(string data) { HttpClient client = new HttpClient(); HttpPost postMethod = new HttpPost(new Uri("http://www.9kw.eu/index.cgi")); MultipartEntity multipartEntity = new MultipartEntity(); postMethod.Entity = multipartEntity; StringBody stringBody = new StringBody(Encoding.UTF8, "apikey", _9kw.apikey); multipartEntity.AddBody(stringBody); StringBody stringBody3 = new StringBody(Encoding.UTF8, "source", "csapi"); multipartEntity.AddBody(stringBody3); StringBody stringBody2 = new StringBody(Encoding.UTF8, "action", "usercaptchaupload"); multipartEntity.AddBody(stringBody2); FileInfo fileInfo = new FileInfo(@data); FileBody fileBody = new FileBody("file-upload-01", data, fileInfo); multipartEntity.AddBody(fileBody); HttpResponse response = client.Execute(postMethod); return(EntityUtils.ToString(response.Entity)); }
public void HttpPostWithFilesAndParameters3() { // this method sends a file and checks for the number of bytes recieved HttpClient client = new HttpClient(); string url = "http://www.fiddler2.com/sandbox/FileForm.asp"; HttpPost postMethod = new HttpPost(new Uri(url)); MultipartEntity multipartEntity = new MultipartEntity(); postMethod.Entity = multipartEntity; string fileName = "small-text.txt"; StringBody stringBody1 = new StringBody(Encoding.ASCII, "1", "1_"); multipartEntity.AddBody(stringBody1); FileInfo fi = ResourceManager.GetResourceFileInfo(fileName); FileBody fileBody1 = new FileBody("fileentry", fileName, fi, "text/plain"); multipartEntity.AddBody(fileBody1); StringBody stringBody2 = new StringBody(Encoding.ASCII, "_charset_", "windows-1252"); multipartEntity.AddBody(stringBody2); HttpResponse response = client.Execute(postMethod); Assert.AreEqual(200, response.ResponseCode); string responseString = EntityUtils.ToString(response.Entity); Assert.AreEqual(url, response.RequestUri.AbsoluteUri); Console.Write(responseString); }
public void HttpPostWithFilesAndParameters() { // this method sends an empty file (or no file :) HttpClient client = new HttpClient(); HttpPost postMethod = new HttpPost(new Uri(Constants.HTTP_MULTIPART_POST_200)); MultipartEntity multipartEntity = new MultipartEntity(); StringBody stringBody1 = new StringBody(Encoding.ASCII, "param1", "value1"); multipartEntity.AddBody(stringBody1); StringBody stringBody2 = new StringBody(Encoding.ASCII, "param2", "!#$^&*((<>"); multipartEntity.AddBody(stringBody2); FileBody fileBody1 = new FileBody("photo", "me.file", null); multipartEntity.AddBody(fileBody1); postMethod.Entity = multipartEntity; HttpResponse response = client.Execute(postMethod); Assert.AreEqual(200, response.ResponseCode); string responseString = EntityUtils.ToString(response.Entity); MessageData md = new MessageData(); md.PostParameters.Add(new NameValuePair("param1", "value1")); md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>")); md.Files.Add(new NameValuePair("me.file", "0")); Assert.AreEqual(md.ToString(), responseString); Assert.AreEqual(Constants.HTTP_MULTIPART_POST_200, response.RequestUri.AbsoluteUri); Console.Write(responseString); }
private void ExecuteWebServiceTest(TestCasConnectivity.TestCasConnectivityRunInstance instance, WebApplication webApplication) { StringBody stringBody = new StringBody("{\"filter\":{\"SearchText\":\"\"},\"sort\":{\"Direction\":0,\"PropertyName\":\"Name\"}}"); stringBody.ContentType = new System.Net.Mime.ContentType("application/json"); string text = "RulesEditor/InboxRules.svc/GetList"; string relativeUrl = "default.aspx"; CasTransactionOutcome casTransactionOutcome = this.BuildOutcome(Strings.CasHealthEcpScenarioTestWebService, Strings.CasHealthEcpTestWebService(new Uri(webApplication.BaseUri, text).ToString()), "ECP Web Sevice Logon Latency", instance); bool flag = false; string additionalInformation = ""; try { TextResponse textResponse = webApplication.Get <TextResponse>(relativeUrl); flag = (textResponse.StatusCode == HttpStatusCode.OK); additionalInformation = (flag ? "" : Strings.CasHealthEcpServiceRequestResult(textResponse.StatusCode.ToString())); base.WriteVerbose(Strings.CasHealthEcpServiceResponse(textResponse.Text)); if (flag) { textResponse = webApplication.Post <TextResponse>(text, stringBody); flag = (textResponse.StatusCode == HttpStatusCode.OK); additionalInformation = (flag ? "" : Strings.CasHealthEcpServiceRequestResult(textResponse.StatusCode.ToString())); base.WriteVerbose(Strings.CasHealthEcpServiceResponse(textResponse.Text)); } } catch (WebException ex) { string casServer = string.Empty; string fullResponse = string.Empty; if (ex.Response != null) { casServer = ex.Response.Headers["X-DiagInfo"]; try { fullResponse = this.GetResponseHtml(ex.Response); } catch (Exception ex2) { if (!(ex2 is ProtocolViolationException) && !(ex2 is IOException) && !(ex2 is NotSupportedException)) { throw; } } } additionalInformation = Strings.CasHealthEcpServiceRequestException(ex.Message, casServer, fullResponse); } casTransactionOutcome.Update(flag ? CasTransactionResultEnum.Success : CasTransactionResultEnum.Failure, additionalInformation); instance.Outcomes.Enqueue(casTransactionOutcome); instance.Result.Outcomes.Add(casTransactionOutcome); }
public string postFile(string session, string fileName) { int GOOD_RETURN_CODE = 200; string subIdLocal = ""; FileStream imageFile = File.OpenRead(fileName); CodeScales.Http.HttpClient httpClient = new CodeScales.Http.HttpClient(); HttpPost httpPost = new HttpPost(new Uri(url + "/api/upload/")); JsonObject jsonObject = getUploadJSON(session); MultipartEntity reqEntity = new MultipartEntity(); StringBody stringBody = new StringBody(Encoding.UTF8, "request-json", jsonObject.ToString()); reqEntity.AddBody(stringBody); FileInfo fileInfo = new FileInfo(fileName); FileBody fileBody = new FileBody("file", fileName, fileInfo); reqEntity.AddBody(fileBody); httpPost.Entity = reqEntity; HttpResponse response = httpClient.Execute(httpPost); String result = ""; int respCode = response.ResponseCode; if (respCode == GOOD_RETURN_CODE) { HttpEntity entity = response.Entity; String content = EntityUtils.ToString(entity); string success = jsonGetValue(content, "status"); subIdLocal = jsonGetValue(content, "subid"); string hash = jsonGetValue(content, "hash"); } return(subIdLocal); }
public void HttpPostWithFilesAndParameters2() { // this method sends a file and checks for the number of bytes recieved HttpClient client = new HttpClient(); HttpPost postMethod = new HttpPost(new Uri(Constants.HTTP_MULTIPART_POST_200)); MultipartEntity multipartEntity = new MultipartEntity(); string fileName = "big-text.txt"; FileInfo fi = ResourceManager.GetResourceFileInfo(fileName); FileBody fileBody1 = new FileBody("file", fileName, fi, "text/plain"); multipartEntity.AddBody(fileBody1); postMethod.Entity = multipartEntity; StringBody stringBody1 = new StringBody(Encoding.ASCII, "param1", "value1"); multipartEntity.AddBody(stringBody1); StringBody stringBody2 = new StringBody(Encoding.ASCII, "param2", "!#$^&*((<>"); multipartEntity.AddBody(stringBody2); HttpResponse response = client.Execute(postMethod); Assert.AreEqual(200, response.ResponseCode); string responseString = EntityUtils.ToString(response.Entity); MessageData md = new MessageData(); md.PostParameters.Add(new NameValuePair("param1", "value1")); md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>")); md.Files.Add(new NameValuePair(fileName, fi.Length.ToString())); Assert.AreEqual(md.ToString(), responseString); Assert.AreEqual(Constants.HTTP_MULTIPART_POST_200, response.RequestUri.AbsoluteUri); Console.Write(responseString); }
public static Class156 IHeader1(string string_0) { StringBody class2 = new StringBody(string_0); return(new Class156(new IHeader1(1, byte_0, (ushort)class2.BodyTotalLength), class2)); }
private void udpClient_DataReceived(IPEndPoint ipendPoint_0, byte[] byte_0) { try { IHeader1 class2 = IHeader1.smethod_0(byte_0); if (class2 != null) { if (class2.method_0() == 0) { IPEndPointBody class4 = IPEndPointBody.smethod_0(byte_0, 4, class2.method_4()); this.OnUdpSessionOpened(class2.method_2(), class4.method_0(), ipendPoint_0, new AgileIPE(class4.method_2(), class4.method_4())); } else if (class2.method_0() == 1) { this.OnUdpSessionOpened(ipendPoint_0, StringBody.smethod_0(byte_0, 4, class2.method_4()).method_0()); } else { Class100 class3; if (class2.method_0() == 2) { class3 = this.safeDictionary_1.Get(ipendPoint_0); if ((class3 != null) && (class3.method_1() == class2.method_2())) { DataFragmentBody class7 = DataFragmentBody.smethod_0(byte_0, 4, class2.method_4()); class3.method_8(class7); } } else if (class2.method_0() == 4) { FeedbackVacancyBody body = FeedbackVacancyBody.Parse(byte_0, 4, class2.method_4()); Class116 class5 = this.safeDictionary_0.Get(ipendPoint_0); if (class5 != null) { class5.method_18(body, true); } } else if (class2.method_0() == 5) { this.method_2(ipendPoint_0); } else if (class2.method_0() == 6) { class3 = this.safeDictionary_1.Get(ipendPoint_0); if (class3 != null) { class3.method_9(); } } else if (class2.method_0() == 7) { class3 = this.safeDictionary_1.Get(ipendPoint_0); if ((class3 != null) && (class3.method_1() == class2.method_2())) { Class154 class8 = Class154.smethod_0(byte_0, 4, class2.method_4()); ushort num = (ushort)(0x2c + class8.BodyTotalLength); this.class32_0.imethod_2(class3.imethod_2(), num); } } } } } catch (Exception exception) { this.emptyAgileLogger_0.Log(exception, "CJFramework.Engine.Udp.Reliable.ReliableUdpEngine.udpClient_DataReceived", ErrorLevel.Standard); } }