mypicturefaded Posted June 22, 2009 Posted June 22, 2009 (edited) I have this VBScript that I am trying to convert to C# and I am a little stuck on what I should be doing. Set Request = CreateObject("MSXML2.DOMDocument.4.0") Request.async = false with Request.appendChild(Request.createElement("fnApiRequest")) .setAttribute "cmd", "QueryLibrary" end with with Request.documentElement.appendChild(Request.createElement("library")) .setAttribute "name", "name of database" .setAttribute "user", "username" .setAttribute "password", "userpassword" end with with Request.documentElement.appendChild(Request.createElement("query")) .text = "myquery" end with ' send request Set HTTP = CreateObject("WinHTTP.WinHTTPRequest.5.1") HTTP.setTimeouts 0, 30000, 30000, 600000 HTTP.SetAutoLogonPolicy 0 HTTP.Open "POST", "thewebsite", false HTTP.Send Request ' receive response if HTTP.status = 200 then Set Response = CreateObject("MSXML2.DOMDocument.4.0") Response.async = false if Response.LoadXML(HTTP.responseText) then Response.save "QueryResponse.xml" if ucase(Response.documentElement.getAttribute("status")) = "OK" then MsgBox Replace(Response.xml, "><", ">" & vbCr & "<"), , "OK Response" 'MsgBox Nodes(1).xml, , "OK Response" else MsgBox Replace(Response.xml, "><", ">" & vbCr & "<"), , "ERROR Response" Err.Raise CLng(Response.selectSingleNode("//number").text), _ Response.selectSingleNode("//source").text, _ Response.selectSingleNode("//description").text end if else MsgBox HTTP.responseText, , "Invalid web service response: " & HTTP.responseText end if else MsgBox HTTP.responseText, , "Response error: " & HTTP.statusText end if Here is the code that I have so far. I just need a step in the right direction. I don't know how I would all those parameters. string strNewValue; string strResponse; // Create the request obj HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://someur.com/page.aspx"); // Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.Credentials = new NetworkCredential("username", "password"); strNewValue = "fnApiRequest" + "¶m1=cmd&parm2=QueryLibrary"; req.ContentLength = strNewValue.Length; // Write the request StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(strNewValue); stOut.Close(); // Do the request to get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); Edited June 22, 2009 by mypicturefaded Quote
Administrators PlausiblyDamp Posted June 23, 2009 Administrators Posted June 23, 2009 Out of interest what is the code trying to do? It might be easier to replicate the end result rather than trying to duplicate the steps involved. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mypicturefaded Posted June 23, 2009 Author Posted June 23, 2009 I am trying to get some XML info from a library. I need to pull out an item ID. If you went to the page, you would have to hit a tab to select the library, and then do a search for the document. Then you would see what you are looking for. I want to get the XML from that. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.