473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

WebClient.UploadData Authentication issue

6
Hi All,
I try to use WebClient.UploadData 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)Unauthorized
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 2326

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

Similar topics

0
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...
4
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:...
3
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...
6
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...
0
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...
3
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...
1
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...
4
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. ...
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.