0

Essentially what I am attempting to do is you enter a piece of information in a textbox and click submit. It'll then check another website to see if the username is available

It'll then return back all findings into a label on my current website.

I have no idea how to go about doing this? Where should I start. Do I require the button that they click to check, redirect them to that website, or can it be run just in the background and check it?

Would this be even possible to do locally to check online usernames?

This may sound very vague, but I think this is as far in depth I can actually go into this.

Brian Elliott
  • 51
  • 1
  • 13
  • Look up "C# HttpRequest" for some info that could be useful. – Jashaszun Jul 15 '15 at 16:36
  • What website are you trying? Methods vary. And I would suggesst WebClient before HttpRequest, being the simpler of the two to use. – Cory Jul 15 '15 at 16:36
  • It's difficult to help with this without more detail. Is there a form on this other website? Is it just a page with a list of usernames? – James Jul 15 '15 at 16:37
  • 2
    For any given website that you want to check, you'll need to figure out *how* to check. Once you can determine an HTTP request and expected response which would determine this (unless the website has an API you can use instead), then you just need to issue that request and parse that response in your code. – David Jul 15 '15 at 16:37
  • @KoBE Ah sure, WebClient is probably better. – Jashaszun Jul 15 '15 at 16:37
  • It's actually for a game. This is where the username would be entered to find out if its available or not - https://news.omertabeyond.net/userhistory . I think I may have found a way about it, by making it simply pull data, using this - http://stackoverflow.com/questions/18065526/pulling-data-from-a-webpage-parsing-it-for-specific-pieces-and-displaying-it – Brian Elliott Jul 15 '15 at 16:37

1 Answers1

2

If you notice, on that site you can check for the names without even using the form simply by using the name in the url.

https://news.omertabeyond.net/userhistory/idontexist

vs

https://news.omertabeyond.net/userhistory/depay

So, the easiest solution would be to do something like this:

string userName = HttpUtility.UrlEncode("idontexist");
string notFoundText = "No player found with this ingame.";
using (WebClient wc = new WebClient())
{
    if (wc.DownloadString("https://news.omertabeyond.net/userhistory/" + userName).Contains(notFoundText))
    {
        // doesn't exist
    }
    else
    {
        // does exist
    }
}

The UrlEncode bit simply makes sure the username is formatted to be used in a url before making the request.

Cory
  • 1,794
  • 12
  • 21
  • Thank you very much! Solved my issue. I appreciate the help. – Brian Elliott Jul 15 '15 at 16:52
  • Just out of curiosity, as you can see the notFoundText string is static. Lets say the person DOES exist, how would I then go about obtaining information such as their "Percentage Online" or something along those lines? As the value of that would change. Marked as solved now too. – Brian Elliott Jul 15 '15 at 17:25
  • It's static simply because the website returns it when no user is found. Parsing out the information for existing users is a different problem. There are various methods of how you could go about that as well. Regex, manual parsing (searching for indexes and puling out substrings), HtmlAgilityPack, just to name a few. – Cory Jul 15 '15 at 17:28