Reputation: 1849
I am migrating from the old HttpURLConnection to the new Apache HttpClient 5 , to crate a connection in the old code I used this snippet of code
URL url = new URL(“url”); HttpURLConnection conn = url.openConnection(); conn.setRequestMethod(“Post”); conn.setaRequestProperty(header,header.value);
In the new code how I avoid to create multiple if statements and objects of HttpGet or HttpPost ?
Because in the old code I pass the http verb directly to the connection and the headers too but in the new code I must do something like this
If(“Post”) { HttpPost post = HttpPost(url); post.addHeader() … And then httpClient.execute(post) If(“Get”) HttpGet get = new HttpGet(url); get.addHeader() And the httpClient.execute(get);
How do I avoid those if statements ?
Upvotes: 0
Views: 105