public override void Run() { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; string responseString = null; try { HttpPut post = new HttpPut(pathToDoc1.ToExternalForm()); StringEntity se = new StringEntity(docJson.ToString()); se.SetContentType(new BasicHeader("content_type", "application/json")); post.SetEntity(se); response = httpclient.Execute(post); StatusLine statusLine = response.GetStatusLine(); Log.D(Test7_PullReplication.Tag, "Got response: " + statusLine); NUnit.Framework.Assert.IsTrue(statusLine.GetStatusCode() == HttpStatus.ScCreated); } catch (ClientProtocolException e) { NUnit.Framework.Assert.IsNull("Got ClientProtocolException: " + e.GetLocalizedMessage (), e); } catch (IOException e) { NUnit.Framework.Assert.IsNull("Got IOException: " + e.GetLocalizedMessage(), e); } httpRequestDoneSignal.CountDown(); }
public override void Run() { HttpClient httpClient = clientFactory.GetHttpClient(); PreemptivelySetAuthCredentials(httpClient); HttpRequestMessage request = null; if (Sharpen.Runtime.EqualsIgnoreCase(method, "PUT")) { HttpPut putRequest = new HttpPut(url.ToExternalForm()); putRequest.SetEntity(multiPart); request = putRequest; } else { if (Sharpen.Runtime.EqualsIgnoreCase(method, "POST")) { HttpPost postRequest = new HttpPost(url.ToExternalForm()); postRequest.SetEntity(multiPart); request = postRequest; } else { throw new ArgumentException("Invalid request method: " + method); } } request.AddHeader("Accept", "*/*"); ExecuteRequest(httpClient, request); }
public virtual ActionResult Edit(int id, int?parentId, HttpPut ignore) { using (new EFUnitOfWork <DbContextT>()) { if (id == 0) { throw new SupermodelException("CRUDControllerBase.Edit[Post]: id == 0"); } var entityItem = RepoFactory.Create <EntityT>().GetById(id); ChildMvcModelT mvcModelItem; try { entityItem = TryUpdateEntity(entityItem, null, out mvcModelItem); if (parentId == null) { var parent = mvcModelItem.GetParentEntity(entityItem); if (parent != null) { parentId = parent.Id; } } } catch (ModelStateInvalidException ex) { DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction return(View(ex.Model)); } return(AfterUpdate(id, parentId, entityItem, mvcModelItem)); } }
public override string put(string uri, string data) { try { // Prepare a request object HttpPut httpPut = new HttpPut(uri); try { // The default http content charset is ISO-8859-1, JSON requires UTF-8 httpPut.setEntity(new stringEntity(data, "UTF-8")); } catch (UnsupportedEncodingException e1) { e1.PrintStackTrace(); return null; } httpPut.setHeader("Content-Type", "application/json"); HttpResponse response = execute(httpPut); } catch(UnknownHostException ex) { } return parseResponse(response); }
protected internal virtual HttpRequestMessage CreateConcreteRequest() { HttpRequestMessage request = null; if (Sharpen.Runtime.EqualsIgnoreCase(method, "GET")) { request = new HttpGet(url.ToExternalForm()); } else { if (Sharpen.Runtime.EqualsIgnoreCase(method, "PUT")) { request = new HttpPut(url.ToExternalForm()); } else { if (Sharpen.Runtime.EqualsIgnoreCase(method, "POST")) { request = new HttpPost(url.ToExternalForm()); } } } return(request); }
public override void Run() { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; string responseString = null; try { HttpPut post = new HttpPut(pathToDoc1.ToExternalForm()); StringEntity se = new StringEntity(docJson.ToString()); se.SetContentType(new BasicHeader("content_type", "application/json")); post.SetEntity(se); response = httpclient.Execute(post); StatusLine statusLine = response.GetStatusLine(); Log.D(ReplicationTest.Tag, "Got response: " + statusLine); NUnit.Framework.Assert.IsTrue(statusLine.GetStatusCode() == HttpStatus.ScCreated); } catch (ClientProtocolException e) { NUnit.Framework.Assert.IsNull("Got ClientProtocolException: " + e.GetLocalizedMessage (), e); } catch (IOException e) { NUnit.Framework.Assert.IsNull("Got IOException: " + e.GetLocalizedMessage(), e); } httpRequestDoneSignal.CountDown(); }
protected internal virtual HttpRequestMessage CreateConcreteRequest() { HttpRequestMessage request = null; if (Sharpen.Runtime.EqualsIgnoreCase(method, "GET")) { request = new HttpGet(url.ToExternalForm()); } else { if (Sharpen.Runtime.EqualsIgnoreCase(method, "PUT")) { request = new HttpPut(url.ToExternalForm()); } else { if (Sharpen.Runtime.EqualsIgnoreCase(method, "POST")) { request = new HttpPost(url.ToExternalForm()); } } } return request; }