How to ignore the certificate check when ssl

For anyone interested in applying this solution on a per request basis, this is an option and uses a Lambda expression. The same Lambda expression can be applied to the global filter mentioned by blak3r as well. This method appears to require .NET 4.5. String url = “https://www.stackoverflow.com”; HttpWebRequest request = HttpWebRequest.CreateHttp(url); request.ServerCertificateValidationCallback += (sender, … Read more

Login to website, via C#

You can continue using WebClient to POST (instead of GET, which is the HTTP verb you’re currently using with DownloadString), but I think you’ll find it easier to work with the (slightly) lower-level classes WebRequest and WebResponse. There are two parts to this – the first is to post the login form, the second is … Read more

How to post JSON to a server using C#?

The way I do it and is working is: var httpWebRequest = (HttpWebRequest)WebRequest.Create(“http://url”); httpWebRequest.ContentType = “application/json”; httpWebRequest.Method = “POST”; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = “{\”user\”:\”test\”,” + “\”password\”:\”bla\”}”; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); } I wrote a library to … Read more

How to send HTTP request in java? [duplicate]

You can use java.net.HttpUrlConnection. Example (from here), with improvements. Included in case of link rot: public static String executePost(String targetURL, String urlParameters) { HttpURLConnection connection = null; try { //Create connection URL url = new URL(targetURL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”); connection.setRequestProperty(“Content-Length”, Integer.toString(urlParameters.getBytes().length)); connection.setRequestProperty(“Content-Language”, “en-US”); connection.setUseCaches(false); connection.setDoOutput(true); //Send request DataOutputStream wr = new … Read more

Make an HTTP request with android

UPDATE This is a very old answer. I definitely won’t recommend Apache’s client anymore. Instead use either: Retrofit OkHttp Volley HttpUrlConnection Original Answer First of all, request a permission to access network, add following to your manifest: <uses-permission android:name=”android.permission.INTERNET” /> Then the easiest way is to use Apache http client bundled with Android: HttpClient httpclient … Read more

Upload files with HTTPWebrequest (multipart/form-data)

Took the code above and fixed because it throws Internal Server Error 500. There are some problems with \r\n badly positioned and spaces etc. Applied the refactoring with memory stream, writing directly to the request stream. Here is the result: public static void HttpUploadFile(string url, string file, string paramName, string contentType, NameValueCollection nvc) { log.Debug(string.Format(“Uploading … Read more