Hack Forums
[C] url exist check [c++] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] url exist check [c++] (/showthread.php?tid=4537720)



url exist check [c++] - midobahr - Nov 14, 2014

hello guys
iam trying to add a url check to an dll but i think there's smth wrong
here's my code
Code
#include <iostream>
#include <windows.h>
#include <wininet.h>
#pragma comment(lib,"Wininet.lib")

bool URLExists(char *pUrl)
{
    HINTERNET hInternet = InternetOpen("ValidURL", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
    bool bValid = false;

    if (hInternet)
    {
        HINTERNET hFile = InternetOpenUrl(hInternet, pUrl, 0, 0, INTERNET_FLAG_RELOAD, 0);

        if (hFile)
        {
            int code = 0;
            DWORD length = sizeof(int);
            HttpQueryInfo(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &length, 0);
            bValid = code == HTTP_STATUS_OK || code == HTTP_STATUS_REDIRECT;
            InternetCloseHandle(hFile);
        }

        InternetCloseHandle(hInternet);
    }

    return bValid;
}

int main()
{
    if (URLExists("the url "))
        std::cout << "URL Exist" << std::endl;
    else
        std::cout << "URL Not Exist" << std::endl;

    system("PAUSE");
    return 0;
}
any one can help in that ? :)


* - 0xDEAD10CC - Nov 14, 2014

How is this a DLL to begin with? What do you think is wrong with the code?


* - midobahr - Nov 15, 2014

dll work with online game server side included an exe prog
which it have to print the cout badly it dont


* - HelloMyNameIsWalter - Nov 15, 2014

Quote: HINTERNET hInternet = InternetOpen("ValidURL", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);


Since you can't seem to form a question, The above useragent and open type could be giving you issues.


* - midobahr - Nov 15, 2014

(Nov 15, 2014 02:21 AM)HelloMyNameIsWalter Wrote:  Since you can't seem to form a question, The above useragent and open type could be giving you issues.
thanks for help but can u explain how to reslove it ?


* - HelloMyNameIsWalter - Nov 15, 2014

Quote: HINTERNET hInternet = InternetOpen("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/29.0", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);


This may or may not fix it, Just a heads up the original code is not a dll.


* - midobahr - Nov 15, 2014

well it's not fixed and how u mean it's not a dll ? :/


* - 0xDEAD10CC - Nov 15, 2014

It's obviously not a DLL because the signature for a DLL is much different.


* - HelloMyNameIsWalter - Nov 15, 2014

(Nov 15, 2014 03:31 PM)midobahr Wrote:  well it's not fixed and how u mean it's not a dll ? :/

Why don't you read up on how to make a DLL rather than just begging for a solution. It should be obvious that this is not a DLL