My classic asp application uses XML Templates to retrieve an XML document via SQL Server 2000 and the MSXML2.ServerXMLHTTP.4.0 object. I need to convert this to asp.net in c# and need to find a good example that will help me accomplish this. I see a lot
of examples using POST and the HttpWebRequest object but I need a simple example using httpWebRequest.Mehod = "GET" to load the XML document created by the SQL Server 2000 XML Template.
// Set 'Method' property of 'HttpWebRequest' class to POST.
myReq->Method = "GET";
ASCIIEncoding^ encodedData = gcnew ASCIIEncoding;
array<Byte>^ byteArray = encodedData->GetBytes( m_SysString );
// Set 'ContentType' property of the 'HttpWebRequest' class to S"application/x-www-form-urlencoded".
myReq->ContentType = "application/x-www-form-urlencoded";
newStream->Write( postArray, 0, byteArray->Length );
//Console::WriteLine( "\nData has been posted to the Uri\n\nPlease wait for the response.........." );
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse^ myResponce = (HttpWebResponse^)( myReq->GetResponse() );
Member
4 Points
47 Posts
HttpWebRequest Example Using "GET"
Nov 05, 2007 12:36 PM|DeskingFan|LINK
Hi All,
My classic asp application uses XML Templates to retrieve an XML document via SQL Server 2000 and the MSXML2.ServerXMLHTTP.4.0 object. I need to convert this to asp.net in c# and need to find a good example that will help me accomplish this. I see a lot of examples using POST and the HttpWebRequest object but I need a simple example using httpWebRequest.Mehod = "GET" to load the XML document created by the SQL Server 2000 XML Template.
I've been unsuccessful searching on the web.
Thanks.
Participant
1190 Points
210 Posts
Re: HttpWebRequest Example Using "GET"
Nov 06, 2007 01:33 PM|foreachbiscuit|LINK
Have you tried using the HttpWebResponse stream?
obviously you can use any class that derives from stream - whatever is appropriate for the response.
See this msdn link for more information:
HttpWebResponse.GetResponseStream Method
foreachbiscuit
blog @ http://foreachbiscuit.wordpress.com
Member
4 Points
47 Posts
Re: HttpWebRequest Example Using "GET"
Nov 06, 2007 02:03 PM|DeskingFan|LINK
Thanks for your suggestion, I actually got this to work yesterday afternoon. Here is the solution:
public static XmlDocument getXMLDocumentFromXMLTemplate(string inURL)
{
HttpWebRequest myHttpWebRequest = null; //Declare an HTTP-specific implementation of the WebRequest class.
HttpWebResponse myHttpWebResponse = null; //Declare an HTTP-specific implementation of the WebResponse class
XmlDocument myXMLDocument = null; //Declare XMLResponse document
XmlTextReader myXMLReader = null; //Declare XMLReader
try
{
//Create Request
myHttpWebRequest = (HttpWebRequest) HttpWebRequest.Create(inURL);
myHttpWebRequest.Method = "GET";
myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";
//Get Response
myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
//Now load the XML Document
myXMLDocument = new XmlDocument();
//Load response stream into XMLReader
myXMLReader = new XmlTextReader(myHttpWebResponse.GetResponseStream());
myXMLDocument.Load(myXMLReader);
}
catch (Exception myException)
{
throw new Exception("Error Occurred in AuditAdapter.getXMLDocumentFromXMLTemplate()", myException);
}
finally
{
myHttpWebRequest = null;
myHttpWebResponse = null;
myXMLReader = null;
}
return myXMLDocument;
}
Contributor
2843 Points
526 Posts
Re: HttpWebRequest Example Using "GET"
Nov 06, 2007 02:50 PM|pbromberg|LINK
You can do all of this in 2 lines of code:
XmlDocument myXMLDocument = new XmlDocument();
myXMLDocument.Load(url);
<a href="http://peterbromberg.net>PeterBromberg.net
Member
4 Points
47 Posts
Re: HttpWebRequest Example Using "GET"
Nov 06, 2007 03:53 PM|DeskingFan|LINK
Thanks, that also worked and so much less code..
Member
3 Points
38 Posts
Re: HttpWebRequest Example Using "GET"
Jul 23, 2008 10:06 AM|bkthomson|LINK
I'm trying to do something similar to the client-side XMLHttpRequest object where I call a web page in my site and pull back the rendered HTML.
I reviewed the thread took the two working example. . in both cases I'm still having problems.
1) With the XMLDocument example
I get receive the following error: "Could not find a part of the path \"C:\\OpenPointOne\\XMLHttpRequest\\Collect.aspx\"."
When I pull the Page.ResolveURL and just call "Collect.aspx" I receive "Could not find file \"C:\\WINDOWS\\system32\\Collect.aspx\"."
I also attempted to use the public static XmlDocument getXMLDocumentFromXMLTemplate(string inURL)
but the errors come out like
myException.Message
Any other suggestions?"Invalid URI: The format of the URI could not be determined."
inURL
"/OpenPointOne/XMLHttpRequest/Collect.aspx"
None
0 Points
1 Post
Re: HttpWebRequest Example Using "GET"
Aug 25, 2011 08:17 AM|Marky2245|LINK
I'm trying to change the URI using the get method, basically I want to send commands to a DVI switch
Am I right by using HttpWebRequest
HttpWebRequest^ myReq = dynamic_cast<HttpWebRequest^>(WebRequest::Create( m_DVIswitch ));
// Set 'Method' property of 'HttpWebRequest' class to POST.
myReq->Method = "GET";
ASCIIEncoding^ encodedData = gcnew ASCIIEncoding;
array<Byte>^ byteArray = encodedData->GetBytes( m_SysString );
// Set 'ContentType' property of the 'HttpWebRequest' class to S"application/x-www-form-urlencoded".
myReq->ContentType = "application/x-www-form-urlencoded";
myReq->ContentLength = byteArray->Length;
Stream^ newStream = myReq->GetRequestStream();
// Uri^ myUri = gcnew Uri(uriString);
// // myUri =myReq->RequestUri();
newStream->Write( postArray, 0, byteArray->Length );
//Console::WriteLine( "\nData has been posted to the Uri\n\nPlease wait for the response.........." );
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse^ myResponce = (HttpWebResponse^)( myReq->GetResponse() );