How to use verb GET with WebClient request?

If you use HttpWebRequest instead you would get more control of the call. You can change the REST verb by the Method property (default is GET) HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(HostURI); request.Method = “GET”; String test = String.Empty; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); test = reader.ReadToEnd(); … Read more

What are the advantages of using a GET request over a POST request?

I generally set up the question as thus: Does anything important change after the request? (Logging and the like notwithstanding). If it does, it should be a POST request, if it doesn’t, it should be a GET request. I’m glad that you call POST requests “slightly” more secure, because that’s pretty much what they are; … Read more

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 can I pass POST parameters in a URL?

You could use a form styled as a link. No JavaScript is required: <form action=”/do/stuff.php” method=”post”> <input type=”hidden” name=”user_id” value=”123″ /> <button>Go to user 123</button> </form> CSS: button { border: 0; padding: 0; display: inline; background: none; text-decoration: underline; color: blue; } button:hover { cursor: pointer; } See: http://jsfiddle.net/SkQRN/

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”);