Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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" + "&param1=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 by mypicturefaded
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...