webrequest

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

一个人想着一个人 提交于 2019-11-27 08:34:05
I am trying to make a request to a web page using WebRequest class in .net. The url that I am trying to read requires Windows Authentication due to which I get an unauthorised exception. How can I pass a windows credentials to this request so that it can authenticate. HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( "http://myapp/home.aspx" ); request.Method = "GET"; request.UseDefaultCredentials = false; request.PreAuthenticate = true; request.Credentials = new NetworkCredential( "username", "password", "domain" ); HttpWebResponse response = (HttpWebResponse)request.GetResponse

C# WebRequest using Cookies

我与影子孤独终老i 提交于 2019-11-27 08:08:30
I have a winforms application i have been working on that runs multiple tests on consumer accounts. The tests require a one time login in order to execute. string paramaters = "authmethod=on&chkRememberMe=on&login-form-type=pwd&password=" + pw.Text + "&userid=" + uid.Text + "&username=" + uid.Text; string strResponse; HttpWebRequest requestLogin = (HttpWebRequest)WebRequest.Create("https://www.url.com/login.form"); requestLogin.Method = "POST"; requestLogin.CookieContainer = cookieJar; requestLogin.ContentType = "application/x-www-form-urlencoded"; requestLogin.ContentLength = paramaters

Can I send webrequest from specified ip address with .NET Framework?

风流意气都作罢 提交于 2019-11-27 07:54:08
I have a server with multi ip addresses. Now I need to communicate with several servers with http protocol. Each server only accept the request from a specified ip address of my server. But when using WebRequest(or HttpWebRequest) in .NET , the request object will choose a ip address automatically. I can't find anyway to bind the request with a address. Is there anyway to do so ? Or I have to implement a webrequest class myself ? You need to use the ServicePoint.BindIPEndPointDelegate callback. http://blogs.msdn.com/b/malarch/archive/2005/09/13/466664.aspx The delegate is called before the

Using HTTP Authentication with a C# WebRequest

微笑、不失礼 提交于 2019-11-27 06:34:21
问题 I want to make a web request to a page that needs authenticating. How would I go about doing this? I found something that said possibly to use the Credentials property, but I'm not sure how to use it. 回答1: Assign a new NetworkCredential instance to the Credentials property: webClient.Credentials = new NetworkCredential("Mehrdad", "Password"); 回答2: Basic auth example: public void SetBasicAuthHeader(WebRequest req, String userName, String userPassword) { string authInfo = userName + ":" +

How to Replace WebClient with HttpClient?

偶尔善良 提交于 2019-11-27 06:21:00
问题 I have the following WebClient inside my asp.net mvc web application: using (WebClient wc = new WebClient()) // call the Third Party API to get the account id { string url = currentURL + "resources/" + ResourceID + "/accounts?AUTHTOKEN=" + pmtoken; var json = await wc.DownloadStringTaskAsync(url); } So can anyone advice how I can change it from WebClient to be HttpClient? 回答1: You can write the following code: string url = currentURL + "resources/" + ResourceID + "/accounts?AUTHTOKEN=" +

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

时光怂恿深爱的人放手 提交于 2019-11-27 06:04:39
Now that SSL 3 has been found to be vulnerable to the POODLE attack: Which versions of SSL/TLS does System.Net.WebRequest use when connecting to any https Uri? I use WebRequest to connect to several 3rd party API's. One of these has now said they will block any request that uses SSL 3. But WebRequest is part of the .Net core framework (using 4.5) so it is not obvious what version it uses. Gareth Williams When using System.Net.WebRequest your application will negotiate with the server to determine the highest TLS version that both your application and the server support, and use this. You can

Mocking WebResponse's from a WebRequest

扶醉桌前 提交于 2019-11-27 05:17:16
问题 I have finally started messing around with creating some apps that work with RESTful web interfaces, however, I am concerned that I am hammering their servers every time I hit F5 to run a series of tests.. Basically, I need to get a series of web responses so I can test I am parsing the varying responses correctly, rather than hit their servers every time, I thought I could do this once, save the XML and then work locally. However, I don't see how I can "mock" a WebResponse, since (AFAIK)

C# WebRequest.getResponse(): 400 Bad Request

时光总嘲笑我的痴心妄想 提交于 2019-11-27 04:42:10
问题 I am trying to download a file from a server using System.Web. It actually works, but some links give me trouble. The links look like this: http://cdn.somesite.com/r1KH3Z%2FaMY6kLQ9Y4nVxYtlfrcewvKO9HLTCUBjU8IBAYnA3vzE1LGrkqMrR9Nh3jTMVFZzC7mxMBeNK5uY3nx5K0MjUaegM3crVpFNGk6a6TW6NJ3hnlvFuaugE65SQ4yM5754BM%2BLagqYvwvLAhG3DKU9SGUI54UAq3dwMDU%2BMl9lUO18hJF3OtzKiQfrC/the_file.ext The code looks basically like this: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link); WebResponse

C# - How to make a HTTP call

三世轮回 提交于 2019-11-27 01:41:54
I wanted to make an HTTP call to a website. I just need to hit the URL and dont want to upload or download any data. What is the easiest and fastest way to do it. I tried below code but its slow and after 2nd repetitive request it just goes into timeout for 59 secounds and than resume: WebRequest webRequest = WebRequest.Create("http://ussbazesspre004:9002/DREADD?" + fileName); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = fileName.Length; Stream os = webRequest.GetRequestStream(); os.Write(buffer, 0, buffer.Length); os

How can I do digest authentication with HttpWebRequest?

蓝咒 提交于 2019-11-27 01:35:14
问题 Various articles (1, 2) I discovered make this look easy enough: WebRequest request = HttpWebRequest.Create(url); var credentialCache = new CredentialCache(); credentialCache.Add( new Uri(url), // request url "Digest", // authentication type new NetworkCredential("user", "password") // credentials ); request.Credentials = credentialCache; However, this only works for URLs without URL parameters. For example, I can download http://example.com/test/xyz.html just fine, but when I attempt to