public static void postXml(string[] args) { RestClient c = new RestClientImpl(new HttpClient()); RestRequest req = new RestRequest(); req.Body = "<resource><name>n</name><data>d1</data></resource>"; req.Resource = "/resources/"; req.Method = RestRequest.Method.Post; RestResponse res = c.execute("http://localhost:8765", req); Console.WriteLine("=======>\n" + res + "\n<======="); string loc = res.getHeader("Location").get(0).Value; req.Resource = loc + ".json"; req.Method = RestRequest.Method.Get; res = c.execute("http://localhost:8765", req); Console.WriteLine("=======>\n" + res + "\n<======="); req.Method = RestRequest.Method.Put; req.Body = "<resource><name>another name</name><data>another data</data></resource>"; res = c.execute("http://localhost:8765", req); Console.WriteLine("=======>\n" + res + "\n<======="); req.Resource = "/resources/"; req.Method = RestRequest.Method.Get; res = c.execute("http://localhost:8765", req); Console.WriteLine("=======>\n" + res + "\n<======="); req.Method = RestRequest.Method.Delete; req.Resource = loc; res = c.execute("http://localhost:8765", req); Console.WriteLine("=======>\n" + res + "\n<======="); }
private IRestClient createConfiguredClient(Config config) { IRestClient client = new RestClientImpl(); client.ReadWriteTimeout = DEFAULT_READWRITE_TIMEOUT; if (config != null) { client.ReadWriteTimeout = config.getAsInteger("http.client.connection.timeout", DEFAULT_READWRITE_TIMEOUT); } return(client); }
public static void postForm(string[] args) { RestClient c = new RestClientImpl(new HttpClient()); RestRequest req = new RestRequest(); req.Body = "name=n&data=d1"; req.Resource = "/resources/"; req.Method = RestRequest.Method.Post; req.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); RestResponse res = c.execute("http://localhost:8765", req); Console.WriteLine("=======>\n" + res + "\n<======="); }