Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

webclient - How to access a web site from a native Windows application?

I hope this is a simple question.

Using .NET, I could simply access a Web site using:

WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("myUserName", "Password123");
string fileContent = wc.DownloadString("https://example.com/example.txt");

Unfortunately, I am working on a native 64-bit DLL file which is used as plug-in in another program.

So I have no chance to use .NET but I can only use native 64-bit Windows DLLs.

Are there any native Windows APIs that do the same as the code above?

I have searched the Internet, but I found nothing.

question from:https://stackoverflow.com/questions/65832658/how-to-access-a-web-site-from-a-native-windows-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found out the answer myself:

The functions of "wininet.dll" are the solution:

The function InternetOpen() more or less corresponds to new WebClient().

Downloading data is a bit more complicated; there is no unified API for different protocols (HTTP, FTP, ...), but each protocol type uses different functions.

To download (GET) or send (POST) data via HTTP or HTTPS, the APIs InternetCrackUrl(), InternetConnect(), HttpSendRequest() and InternetReadFile() are used.

(Note: On the Microsoft web site documentation, the function declarations are shown as void InternetOpen(...) although the documentation says that the functions return a value of the type HINTERNET. HINTERNET is correct, void is wrong.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...