By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

send data on remote server

P: 1
Hello All,

i am open this URL( directly in browser with enter credential then its open and show xml data. but if i used this url in code means i send Requset and post data on server then i am getting Error(The remote server returned an error: (401) Unauthorized.) here i used same credentials.

I send request by this code.
Expand|Select|Wrap|Line Numbers
  1. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("");
  2. myHttpWebRequest.Method = "POST";
  3. string postData = "?actor=";
  4. byte[] byte1 = Encoding.UTF8.GetBytes(postData); 
  5. myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
  6. myHttpWebRequest.ContentLength = byte1.Length;
  7. myHttpWebRequest.Credentials = new NetworkCredential("", "topia1", "id.skootit");
  8. Stream newStream = myHttpWebRequest.GetRequestStream();
  9. newStream.Write(byte1, 0, byte1.Length);
  10. newStream.Close();
  14. //(on this line i m getting error.)
  15. WebResponse response = myHttpWebRequest.GetResponse();
  18. newStream = response.GetResponseStream();
  19. StreamReader reader = new StreamReader(newStream);
  20. string responseFromServer = reader.ReadToEnd();
  21. Console.WriteLine(responseFromServer);
  22. reader.Close();
  23.  newStream.Close();
  24.  response.Close();
when execute this code then i got error (The remote server returned an error: (401) Unauthorized.)

System.Net.WebException was unhandled
Message="The remote server returned an error: (401) Unauthorized."
at System.Net.HttpWebRequest.GetResponse()
at ConsoleApplication2.Program.Main(String[] args) in C:\Documents and Settings\nidhi\My Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplicati on2\Program.cs:line 71
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

please help me how to solve this error??
Dec 20 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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