473,549 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebClient.Uploa dData Authentication issue

6 New Member
Hi All,
I try to use WebClient.Uploa dData to upload a photo with the size less than 1MB to my local IIS.

I setup my IIS by adding a new virtual directory with the write access to the photo (Please refer to the figure below for better understanding).



After that, I edit the photo's directory security by clearing up the anonymous access checkbox and check/tick the Integrated Windows authentication. (Please refer to the figure below)



At the end I write the following code to upload the photo. Assuming that my computer login is compaq, password is 1234abcd without join domain and proxy.

Expand|Select|Wrap|Line Numbers
  1. using (WebClient Client = new WebClient())
  2. {
  3.   using(FileStream fs = File.OpenRead("C:\abc.jpg"))
  4.   {
  5.      byte[] data = new byte[fs.Length];
  6.      fs.Read(data, 0, data.Length);
  7.      CredentialCache cache = new CredentialCache();
  8.      Uri UploadPhotoDircectory = new Uri("http://localhost/FFQWS/Photo/");
  9.      string AuthType = "Negotiate";
  10.      cache.Add(UploadPhotoDircectory, AuthType, new System.Net.NetworkCredential("compaq", "1234abcd"));
  11.      Client.Credentials = cache;
  12.      try
  13.      {
  14.         Client.UploadData("http://localhost/FFQWS/Photo/abc.jpg", "PUT", data);
  15.      }
  16.      catch(Exception ex)
  17.      {
  18.         MessageBox.Show(ex.Message);
  19.      }
  20. }
Alas, after UploadData I get the following exception.
The remote server returned an error:(401)Unau thorized
I already searched through the internet and comfirmed that I did insert the valid windows login. Hope that someone can help me to solve the issue. Your help is really very appreciated. Thank you very much. ^^
Feb 23 '09 #1
0 2340

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1297
by: Ramkrishna Kulkarni | last post by:
Hi, We are using UploadData method of WebClient class in C# to establish connection(s) between two machines(typical client/server). Connection is established if the machines are on same domain. If machines are on different domains client state is SYN_SENT (and not ESTABLISHED as expected). This problem does not arise if we use sockets. Is...
4
10308
by: Paul J. Lay | last post by:
I am sending and receiving multipart messages using the WebClient UploadData method Method=Post. Everything seems to work well except when the URL contains parameters. For example: http://www.someURL.com?parm1=data1&parm2=data2. I don't believe these paramters are transmitted as part of the URL with the HTTP Post interface. I was under the...
3
2893
by: bss2004 | last post by:
Help! I'm posting a PDF Doc to a remote server using WebClient UploadData and the following code. The DOC posts fine and the server returns a positive response. If I access the remote file in Firefox the Adobe PDF Reader in Firefox kicks off and I can view the file just fine. HOWEVER, if I try to access the file using Internet Explorer...
6
4314
by: Russell Stevens | last post by:
I use a WinForm app for users to upload a file to my server. Basically one line of code; Response = WC.UploadData(MyUrl, "PUT", MyByteArray) Works fine except for larger files. After about 104 seconds I get a System.Net.WebException in System.dll. The message is "The operation has timed out". On my server, I have modified the...
0
1424
by: Mark | last post by:
I have a very strange problem that is driving me nuts. My application is using the webclient object to send data to a webserver running on a unix box. We use 2 different environments, 1 for development and 1 for a staging environment. I'm using an invalid servlet name in the url deliberately in order to test my logic for basic communication...
3
1946
by: Philip Wagenaar | last post by:
Hello, I have a executeble that sends a request to a webserver: Return Encoding.UTF8.GetString(myWebClient.UploadData(uri, "POST", Encoding.UTF8.GetBytes(postString))) We are a having a problem that if we run it multiple times in a short time span something fails. ANd I was wondering if the webclient could be the cause of problems.
1
1740
by: Rippo | last post by:
Hi I need to post a form to an external URL, get a repsonse, then repost to an external URL and redirect at the same time. I can figure out step 1 and step 2 fine but I cant seem to figure out how to send a form and send the client to the external url at the same time. Can anyone help? 'Step 1 create form data Dim formPostData As String...
4
7754
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. The problem is, certain cookies need to be set, and the only way of doing that is not letting the WebClient automatically go on to the next GET in...
2
3937
by: Tosco | last post by:
I read many examples with NetworkCredential and WebClient, but no one with a real http address. They all work in theory, but I wasn't able to use them in the real world. The following code should access an ebay page. There is no redirection involved in TestPage. If you have an ebay account you can try it in 1 minute. What's wrong with...
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7462
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.