Socket implements HTTP client

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.