Wininet was used as a project some days ago. Powerful. However, it is inconvenient to manage cookies. Even if you set up to manually manage cookies. This day, the pie is still happening. For example, if you used a browser to access this site and left a cookie and you used wininet to access the site, this pie appeared.
Packets are not difficult to connect. Heap headers. Data is generated after two linefeeds (post only ).
How do I know the length of the data returned by the server? We know the Content-Length header. But packet capture is found. Some static files do not exist. Its length is stored after two linefeeds. A separate row is saved in hexadecimal text format.
For example:
HTTP/1.1 200 OK
Date: sat, 04 Jul 2009 17:41:10 GMT
Server: Apache
Pragma: No-Cache
Connection: keep-alive
Content-Type: text/plain
2f8
......
Here the red 2f8 is the length of the body.
Another method to control the connection behavior is the connection header. If it is keep-alive, do not disconnect the connection after a request is completed. My practice here is to save the last domain name and port. If the last request has keep-alive and the domain name and port have not changed. There is no need to reconnect.
After the packet processing is completed. Some interfaces are encapsulated. Note the following details. The first letter of all words not in the protocol header is in uppercase. I did not pay attention to the encapsulation, and it took a lot of detours.
This basically satisfies my project requirements. Use it as a QQ account registrar. Fast. There will be no "illegal access. Great!
The last problem is encoding recognition and processing. If it is text, there must be encoding recognition. This part has not been implemented yet. No good solution found.
Note: The above content is implemented in easy language. If you need source code, contact me.