Passing a list of int to a HttpGet request

If you are using MVC WebAPI, then you can declare your method like this: [HttpGet] public int GetTotalItemsInArray([FromQuery]int[] listOfIds) { return listOfIds.Length; } and then you query like this: blabla.com/GetTotalItemsInArray?listOfIds=1&listOfIds=2&listOfIds=3 this will match array [1, 2, 3] into listOfIds param (and return 3 as expected)

How do I print the content of httprequest request?

You can print the request type using: request.getMethod(); You can print all the headers as mentioned here: Enumeration<String> headerNames = request.getHeaderNames(); while(headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); System.out.println(“Header Name – ” + headerName + “, Value – ” + request.getHeader(headerName)); } To print all the request params, use this: Enumeration<String> params = request.getParameterNames(); while(params.hasMoreElements()){ String …

Read more

HttpPost vs HttpGet attributes in MVC: Why use HttpPost?

Imagine the following: [HttpGet] public ActionResult Edit(int id) { … } [HttpPost] public ActionResult Edit(MyEditViewModel myEditViewModel) { … } This wouldn’t be possible unless the ActionMethodSelectorAttributes HttpGet and HttpPost where used. This makes it really simple to create an edit view. All the action links just points right back to the controller. If the view …

Read more

HTTP GET in VB.NET

In VB.NET: Dim webClient As New System.Net.WebClient Dim result As String = webClient.DownloadString(“http://api.hostip.info/?ip=68.180.206.184”) In C#: System.Net.WebClient webClient = new System.Net.WebClient(); string result = webClient.DownloadString(“http://api.hostip.info/?ip=68.180.206.184”);

How to add query parameters to a HTTP GET request by OkHttp?

For okhttp3: private static final OkHttpClient client = new OkHttpClient().newBuilder() .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .build(); public static void get(String url, Map<String,String>params, Callback responseCallback) { HttpUrl.Builder httpBuilder = HttpUrl.parse(url).newBuilder(); if (params != null) { for(Map.Entry<String, String> param : params.entrySet()) { httpBuilder.addQueryParameter(param.getKey(),param.getValue()); } } Request request = new Request.Builder().url(httpBuilder.build()).build(); client.newCall(request).enqueue(responseCallback); }

Writing image to local server

A few things happening here: I assume you required fs/http, and set the dir variable 🙂 google.com redirects to www.google.com, so you’re saving the redirect response’s body, not the image the response is streamed. that means the ‘data’ event fires many times, not once. you have to save and join all the chunks together to …

Read more