webclient

Authenticating ASP.NET MVC user from a WPF application

时光总嘲笑我的痴心妄想 提交于 2019-12-03 14:09:13
问题 How can I authenticate a user (with username and password) of an ASP.NET MVC application? I'm trying to do this using WebClient , passing NetworkCredentials , posting the request to the ASP.NET MVC application from my WPF client. How do I handle this request on the server? How do I get the passed username and password? I'm using forms authentication in the ASP.NET MVC app (the default that is created with a new project). 回答1: Forms authentication works in two steps: The user goes to the LogIn

C# WebClient NTLM authentication starting for each request

风格不统一 提交于 2019-12-03 12:52:48
问题 Consider a simple C# NET Framework 4.0 application, that: uses WebClient authenticates using NTLM (tested on IIS 6.0 and IIS 7.5 server) retrieves a string from an URL multiple times using DownloadString() Here's a sample that works fine: using System; using System.Net; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string URL_status = "http://localhost/status"; CredentialCache myCache = new CredentialCache(); myCache.Add(new Uri(URL_status), "NTLM", new

Is there a way to do a PUT with WebClient?

自古美人都是妖i 提交于 2019-12-03 10:24:21
with the WebClient class in .NET 4.0, is there a way to do a PUT? I know you can do a GET with DownloadString() and a POST with UploadString(), but is there a method or property that lets you do a PUT? Thanks. There are overloads for UploadString that let you specify the method. For example, this one takes a Uri , a string for the method, and a string for the data. You can use webclient.UploadString (urlwithparams,"Put","") url with params should include the params in querystring format ... urlwithparams = www.foo.com?key=value&key2=value2 This worked for me... Huh? As stated on MS's website

Client Web Browser Behavior When Handling 301 Redirect

偶尔善良 提交于 2019-12-03 10:05:27
The RFC seems to suggest that the client should permanently cache the response: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 10.3.2 301 Moved Permanently The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise. The new permanent URI SHOULD be given by the Location field in

How to use verb GET with WebClient request?

大憨熊 提交于 2019-12-03 09:10:52
问题 How might I change the verb of a WebClient request? It seems to only allow/default to POST, even in the case of DownloadString. try { WebClient client = new WebClient(); client.QueryString.Add("apiKey", TRANSCODE_KEY); client.QueryString.Add("taskId", taskId); string response = client.DownloadString(TRANSCODE_URI + "task"); result = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(response); } catch (Exception ex ) { result = null; error = ex.Message + " " + ex.InnerException; } And

Add request headers with WebClient C#

感情迁移 提交于 2019-12-03 08:32:43
I have the following code with which I download a web-page into a byte array and then print it with Response.Write: WebClient client = new WebClient(); byte[] data = client.DownloadData(requestUri); /*********** Init response headers ********/ WebHeaderCollection responseHeaders = client.ResponseHeaders; for (int i = 0; i < responseHeaders.Count; i++) { Response.Headers.Add(responseHeaders.GetKey(i), responseHeaders[i]); } /***************************************************/ Besides of the response headers, I need to add request headers as well. I try to do it with the following code: /******

Read response header from WebClient in C#

不问归期 提交于 2019-12-03 05:54:09
I'm trying to create my first windows client (and this is my fist post her), there shall communicate with a "web services", but i have some trouble to read the response header there is coming back. In my response string do I received a nice JSON document back (and this is my next problem), but i'm not able to "see/read" the header in the response, only the body. Below is the code i'm using. WebClient MyClient = new WebClient(); MyClient.Headers.Add("Content-Type", "application/json"); MyClient.Headers.Add("User-Agent", "DIMS /0.1 +http://www.xxx.dk"); var urlstring = "http://api.xxx.com/users/

Difference between shouldoverrideurlloading and shouldinterceptrequest?

本小妞迷上赌 提交于 2019-12-03 03:38:26
问题 Anyone please tell me the difference between methods public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request) and public boolean shouldOverrideUrlLoading(WebView view, String url) . I'm creating an android application in which a string is got as the response of a click event in my WebView .I want to store this string and display it.I saw both of these methods.I tried using shouldOverrideUrlLoading which returns the redirect url when i checked with creating

C# WebClient NTLM authentication starting for each request

只愿长相守 提交于 2019-12-03 03:15:28
Consider a simple C# NET Framework 4.0 application, that: uses WebClient authenticates using NTLM (tested on IIS 6.0 and IIS 7.5 server) retrieves a string from an URL multiple times using DownloadString() Here's a sample that works fine: using System; using System.Net; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string URL_status = "http://localhost/status"; CredentialCache myCache = new CredentialCache(); myCache.Add(new Uri(URL_status), "NTLM", new NetworkCredential("username", "password", "domain")); WebClient WebClient = new WebClient(); WebClient

Emulate XmlHttpRequest with a .NET WebClient

我的未来我决定 提交于 2019-12-03 00:28:28
AFAIK with XmlHttpRequest I can download and upload data just with the send method. But WebClient has plenty of methods. I don't want all the functionality of a WebClient . I just want to create an object that emulates a XmlHttpRequest , except that it doesn't have XSS restrictions. I also don't care about getting the response as an XML or even as a string right now. If I can get it as an array of bytes that's good enough. I thought that I could use the UploadData as my universal method, but it fails when trying to download data with it even though it returns a response. So how can I write a