Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

401 Error on RequestStream

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Luis Esteban Valencia - 07 Jul 2005 17:53 GMT
Hello. I am making the practice of chapter 6. Biztalk Unleashed its about
sending an HTTP request with a c# webform.

I got this error
Unable to complete web request. Web Exception error: Error en el servidor
remoto: (401) No autorizado.

This is the code of the submit button.

private void btnsubmit_Click(object sender, System.EventArgs e)

{

string requestLocation =
"http://localhost:90/HTTPSender/BTSHTTPReceive.dll";

Status.Text = "";

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.PreserveWhitespace = true;

XmlNode tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element,
"Activity", "http://que.activity");

xmlDocument.AppendChild(tempXmlNode);

tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Attribute, "type", "");

tempXmlNode.Value = TypeList.SelectedItem.Text;

xmlDocument.DocumentElement.Attributes.Append( (XmlAttribute)tempXmlNode);

tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "Location", "");

tempXmlNode.InnerText = Location.Text;

xmlDocument.DocumentElement.AppendChild(tempXmlNode);

tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "Timestamp", "");

DateTime now = DateTime.Now;

tempXmlNode.InnerText = now.ToString("s");

xmlDocument.DocumentElement.AppendChild(tempXmlNode);

tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "Notes", "");

tempXmlNode.InnerText = Notes.Text;

xmlDocument.DocumentElement.AppendChild(tempXmlNode);

try

{

HttpWebRequest request = (HttpWebRequest)
HttpWebRequest.Create(requestLocation);

request.Method = "POST";

ASCIIEncoding encoding = new ASCIIEncoding();

byte[] requestData = encoding.GetBytes(xmlDocument.OuterXml);

request.ContentType="application/x-www-form-urlencoded";

request.ContentLength = xmlDocument.OuterXml.Length;

Status.Text += "Submitting activity message";

Stream requestStream = request.GetRequestStream();   ---------->ERROR HERE

requestStream.Write(requestData,0,requestData.Length);

requestStream.Flush();

requestStream.Close();

HttpWebResponse response = (HttpWebResponse) request.GetResponse();

StreamReader responseData = new StreamReader( response.GetResponseStream());

Status.Text = System.Web.HttpUtility.HtmlEncode( responseData.ReadToEnd()) +
"<br>";

}

catch (WebException wex)

{

Status.Text = "Unable to complete web request. Web Exception error: " +
wex.Message;

}

}

Thanks
Joerg Jooss - 08 Jul 2005 17:11 GMT
> Hello. I am making the practice of chapter 6. Biztalk Unleashed its
> about sending an HTTP request with a c# webform.
>
> I got this error
> Unable to complete web request. Web Exception error: Error en el
> servidor remoto: (401) No autorizado.
[...]

You're sending neither a NetworkCredential object nor any form data
that may authenticate you.

Cheers,
Signature

http://www.joergjooss.de
mailto:news-reply@joergjooss.de

Luis Esteban Valencia - 08 Jul 2005 17:51 GMT
I already changed it
and added this line
request.Credentials = new NetworkCredential("btservices", "xxxxx", "se");

after it I got this message

Unable to complete web request. Web Exception error: Error en el servidor
remoto: (405) Método no permitido.

> > Hello. I am making the practice of chapter 6. Biztalk Unleashed its
> > about sending an HTTP request with a c# webform.
[quoted text clipped - 8 lines]
>
> Cheers,
Joerg Jooss - 08 Jul 2005 20:02 GMT
> I already changed it
> and added this line
> request.Credentials = new NetworkCredential("btservices", "xxxxx",
> "se");
>
> after it I got this message

Does the problem still exist? If it does, the web application uses
forms authentication, in which case you need to post your credentials
as form data.

Cheers,
Signature

http://www.joergjooss.de
mailto:news-reply@joergjooss.de


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.