Reasons for a 409/Conflict HTTP error when uploading a file to sharepoint using a .NET WebRequest?

Since no answers were posted, I found the following here: The Web server (running the Web site) thinks that the request submitted by the client (e.g. your Web browser or our CheckUpDown robot) can not be completed because it conflicts with some rule already established. For example, you may get a 409 error if you … Read more

Making a web request to a web page which requires windows authentication

You should use Credentials property to pass the windows credentials to the web service. If you wish to pass current windows user’s credentials to the service then request.Credentials = CredentialCache.DefaultCredentials; should do the trick. Otherwise use NetworkCredential as follows: request.Credentials = new NetworkCredential(user, pwd, domain);

HttpWebRequest: Add Cookie to CookieContainer -> ArgumentException (Parametername: cookie.Domain)

CookieContainers can hold multiple cookies for different websites, therefor a label (the Domain) has to be provided to bind each cookie to each website. The Domain can be set when instantiating the individual cookies like so: Cookie chocolateChip = new Cookie(“CookieName”, “CookieValue”) { Domain = “DomainName” }; An easy way to grab the domain to … Read more

Test if a website is alive from a C# application

HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response == null || response.StatusCode != HttpStatusCode.OK) As @Yanga mentioned, HttpClient is probably the more common way to do this now. HttpClient client = new HttpClient(); var checkingResponse = await client.GetAsync(url); if (!checkingResponse.IsSuccessStatusCode) { return false; }

Forcing Basic Authentication in WebRequest

I’ve just found this very handy little chunk of code to do exactly what you need. It adds the authorization header to the code manually without waiting for the server’s challenge. public void SetBasicAuthHeader(WebRequest request, String userName, String userPassword) { string authInfo = userName + “:” + userPassword; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); request.Headers[“Authorization”] = “Basic ” … Read more

Mono https webrequest fails with “The authentication or decryption has failed”

I had the same problem with Unity (which also uses mono) and this post helped me to solve it. Just add the following line before making your request: ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; And this method: public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { bool isOk = true; // If there are errors in … Read more

Which versions of SSL/TLS does System.Net.WebRequest support?

This is an important question. The SSL 3 protocol (1996) is irreparably broken by the Poodle attack published 2014. The IETF have published “SSLv3 MUST NOT be used”. Web browsers are ditching it. Mozilla Firefox and Google Chrome have already done so. Two excellent tools for checking protocol support in browsers are SSL Lab’s client … Read more

How do you send an HTTP Get Web Request in Python? [duplicate]

You can use urllib2 import urllib2 content = urllib2.urlopen(some_url).read() print content Also you can use httplib import httplib conn = httplib.HTTPConnection(“www.python.org”) conn.request(“HEAD”,”/index.html”) res = conn.getresponse() print res.status, res.reason # Result: 200 OK or the requests library import requests r = requests.get(‘https://api.github.com/user’, auth=(‘user’, ‘pass’)) r.status_code # Result: 200

How to get json response using system.net.webrequest in c#?

Some APIs want you to supply the appropriate “Accept” header in the request to get the wanted response type. For example if an API can return data in XML and JSON and you want the JSON result, you would need to set the HttpWebRequest.Accept property to “application/json”. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri); httpWebRequest.Method = WebRequestMethods.Http.Get; httpWebRequest.Accept … Read more