Is this possible with .NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • delcom5
    New Member
    • Aug 2007
    • 4

    Is this possible with .NET

    Hi,
    I am tasked with a small project. I have to create an app that can login to a website, navigate to a page from their menu, then on the popup page, select an item, on the next popup, grab the data I am looking for and verify if with our system.

    I have to validate some information I have in our system with one of our suppliers. So e.g for items A, B and C I need to verify their quantity amount on their website.

    Where can I find some information on doing this or can someone just provide me a short sample to get started?

    Thanks
  • phvfl
    Recognized Expert New Member
    • Aug 2007
    • 173

    #2
    Hi,

    This would be possible, but quite involved.

    The method that you would be using would be to send a http request to your supplier's website and parsing the reply. This would probably involve multiple requests unless it is possible to attach a cookie to the request that signals that you are logged in.

    You may wish to contact your supplier to find out if they offer an system for making automated enquiries such as this, such as a web service. Many companies would frown on automated requests such as this as it could enable you to make a massive number of automated requests to their site which could affect the performance of their site.

    Comment

    • chazcross
      New Member
      • Feb 2007
      • 31

      #3
      Yes, I have done the same thing in a previous project.

      This http post class and the SGMLreader (html to xml, get it while its still being hosted here) will be your best friends.

      You can find a few articles on the net on using the SGMLreader.
      I used it to do xpath queries to get the data I needed from the http response.
      I used Visual Xpath to create the queries for me.

      Its going to take a while to get everything to work right and your going to spend alot of time in the debugger. If the site your going to do this to uses cookies, get back to me and ill save you a good 10 hours of hair pulling.

      Comment

      • chazcross
        New Member
        • Feb 2007
        • 31

        #4
        here is a small sample of code you will be using
        Code:
        //send our post to a asp.net url
        PostSubmitter post = new PostSubmitter();
        post.Type = PostSubmitter.PostTypeEnum.Post;
        post.Url = url;
        
        post.PostItems.Add("TextBox1", _userName);
        post.PostItems.Add("TextBox2", _password);
        post.PostItems.Add("__EVENTTARGET", "Command1");
        post.PostItems.Add("__EVENTARGUMENT", "");
        post.PostItems.Add("__ET", "");
        httpResponse = post.Post();
        
        //turn the html into a xml doc we can query
        		SgmlReader reader = new SgmlReader();
        		reader.DocType = "HTML";
        		StreamReader sReader = new StreamReader(httpResponse.GetResponseStream());
        		reader.InputStream = new StringReader(sReader.ReadToEnd());
        
        
        		StringWriter sw = new StringWriter();
        		XmlTextWriter writer = new XmlTextWriter(sw);
        		writer.Formatting = Formatting.Indented;
        		while (reader.Read())
        		{
        			if (reader.NodeType != XmlNodeType.Whitespace)
        			{
        				writer.WriteNode(reader, true);
        			}
        		}
        
        		response = sw.ToString();
        
        		XmlDocument xdoc = new XmlDocument();
        //be sure to use debugger here to save xml to file for use with visual xpath
        		xdoc.LoadXml(sw.ToString());
        
        		//select some of the data from one of the html elements on the page
        		StringBuilder sbAction = new StringBuilder();
        		XPathNavigator navAction = xdoc.CreateNavigator();
        		XPathNodeIterator nodesAction = navAction.Select("/html/body/form/@action");
        		while (nodesAction.MoveNext())
        		{
        			sbAction.Append(nodesAction.Current.Value + "\n");
        		}

        Comment

        Working...