Use the Wininet method to achieve the page reading (GET mode)

xiaoxiao2021-03-06  111

Use the Wininet method to implement the page readings. The first part is to use the GET method, the second part is used in the POST method. GET methods and post methods are two ways to send data to web pages. Detailed differences between them can check the RFC document, but simply, you read "http://server/cgi.dll? A = 1 & b = 2 & c = 3 & D = 4 "This page, you will send A = 1, B = 2, C = 3, D = 4," http://server/cgi.dll "page. Numerical value. Looking back, several classes of online transmission, CinternetSession and ChttpFile; ChttpFile is a subclass of CSTDIOFILE, as long as one file on the network is opened with chttpfile, you can be astring as Cstdiofile, so just use the CinternetSession class. This file is OK. The following procedure is the Chinese URL Self-Service Source program that looks for new templates from the Internet and imported. The program first get the handle with sess.openurl (StrfileName), then use fileget-> queryInfo to find if the file exists. According to the HTTP protocol, if this file is present and everything is normal, the return value is between 200-300. The rest of the thing is the normal text file reading:

While (fileget-> readstring (strSentence))

FileWrite.writestring (strSentence "/ n");

FileWrite.Close ();

Mastering the technique of reading a web page, and you can send data with a GET method, such as change StrWritename to "progsave.asp? Curl = Chinese & http = http://www.chinaren.com" you can Squirrel home submits your Chinese website.

However, the GET method is sent to send data has a limit, which is that the transmitted data cannot be too long. I didn't find the specific value, but when the length of Strwritename is greater than 3000 bytes, it will be wrong. In order to allow users to transmit more Chinese websites at a time, I took POST to send. Of course, the POST mode also has a length limit, but it is much longer than GET. Please see next:

Send data with a POST method

The following procedure is debugged on NT4, Visual C6.0.

CString strwritename = "template01.htm"

#ifndef _debug

Strfilename = "http://www.fadshop.net/curl/" strwritename;

#ELSE // If the debug version is read on the IIS of this unit.

Strfilename = "http:// mycomputer / fadshop / curl /" strwritename

#ENDIF

CinternetSession sess; // Establish a session

Chttpfile * fileget;

CEXCEPTION * E;

Try

{

Fileget = (chttpfile *) sess.openurl (StrfileName); // Open file

}

Catch_all (e)

{

Fileget = 0;

}

END_CATCH_ALL

IF (Fileget)

{

DWORD DWSTATUS;

DWORD DWBUFFLEN = SizeOf (DWSTATUS);

Bool bsuccess = fileget-> queryinfo (http_query_status_code | http_query_flag_number,

& DWSTATUS, & DWBUFFLEN;

IF (BSuccess && DWSTATUS> = 200 && DWSTATUS <300)

{CSTDIOFILE FILEWRITE;

IF (FileWriteName, CFile :: ModeWrite | CFILE :: Modecreate))

{While (fileget-> readstring (strsentence)) {

FileWrite.writestring (strSentence "/ n");

}

FileWrite.Close ();

Setdlgitemtext (IDC_DOWNMSG, "Download, is importing ...");

Import this file and have nothing to do with this topic

} // if OpenFile success.

Else

Setdlgitemtext (IDC_DOWNMSG,

"Local file" strwritename "open error / n Please check if your hard disk is free.");

} // if bsuccess.

Else

Setdlgitemtext (IDC_DOWNMSG,

"There is no updated Chinese website template / n, please execute it next time, or go to Squirrel home to view the latest information.");

Fileget-> close ();

DELETE Fileget;

}

Else

Setdlgitemtext (IDC_DOWNMSG, "network is not accessible, please check your network connection.");

sess.close ();

转载请注明原文地址:https://www.9cbs.com/read-96367.html

New Post(0)