CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2013
    Posts
    6

    How to get country from webpage

    Hi! Well I need to get the country automatically from code to show in my app. Well, I found this page: http://api.hostip.info/country.php which gives to you the country code like I need. But I don´t know if there are any form to get this from code. I hope someone can help me. Thanks in advance.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to get country from webpage

    Is this a visual c++ question or a web page scripting question??
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Nov 2013
    Posts
    6

    Re: How to get country from webpage

    Visual c++ question. I only want to know if it is possible to get the country name from a web page like the one I put before or it´s impossible. Or download the content as string or txt...

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to get country from webpage

    How is it a Visual C++ question?

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to get country from webpage

    Quote Originally Posted by varis View Post
    Visual c++ question. I only want to know if it is possible to get the country name from ...
    May I ask you why you need it?
    Victor Nijegorodov

  6. #6
    Join Date
    Nov 2013
    Posts
    6

    Re: How to get country from webpage

    Quote Originally Posted by VictorN View Post
    May I ask you why you need it?
    For my app. I have a label who tell the country of the user and I want to get from that page but I don´t know how to.

    Right, it´s a visual C++ question, I´m using c++ on visual studio 2010. I can´t understand why people still thinking that I´m not using c++ xD, and why is important.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to get country from webpage

    Define "the country of the user".
    And who is about to provide this information?
    Victor Nijegorodov

  8. #8
    Join Date
    Nov 2013
    Posts
    6

    Re: How to get country from webpage

    Well, in that page, tells you the country (in this form: US, UK, ES...) where you live from your ip, and I need exactly that.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to get country from webpage

    Then use WinInet API to connect to http://api.hostip.info/country.php or any similar site to obtain country name.
    Or you could download and then use the database containing country names with the IP Addresses:
    http://www.developerfusion.com/artic...ddress-how-to/
    Victor Nijegorodov

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to get country from webpage

    I guess, URLDownloadToFile function is the simplest way for you to get that info. Save it to some file in %TEMP% folder, and read it whenever you need it.
    Best regards,
    Igor

  11. #11
    Join Date
    Nov 2013
    Posts
    6

    Re: How to get country from webpage

    Hi again. Thanks for the answers. I found URLDownloadToFile more easier to use but I have a problem. If I create a new project works perfect, but If I use on my project I have a problem with UrlMon.h.

    UrlMon.h: No such file or directory

    But I don´t know why I have this problem in one project and not in the other :S. I have the directory C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include in the project aswell.

    Any idea?

  12. #12
    Join Date
    Nov 2013
    Posts
    6

    Re: How to get country from webpage

    Ok, was a mistake of linking librarys. All works perfect now. Thanks for the replies and help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured