How to communicate with a Web server using the socket API

Source: Internet
Author: User

In fact, this problem as long as the Request page HTTP content clear to solve.

The HTTP headers are requested as follows:

Get your URL http/1.1

Accept:image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg, Application/vnd.ms-powerpoint, application/ Vnd.ms-excel, Application/msword, Application/x-shockwave-flash, */*//required to return the content, such as the need to return pictures or flash, etc., I usually have the server to return only text/ HTML, mainly to speed up.

Language used by accept-language:zh-cn//

user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; MYIE2)//Here is mainly to tell the server your IE version number, the use of the system and the use of the browser, in fact, if you want to hide the content here, you can modify it.

Host:www.paymesurf.com//server address

Proxy-connection:keep-alive

The above is basically HTTP content, in the use of the process you need to pay attention to the following points:

1 when sending the requested content, be sure to add another + #13 #10

Httpstr:=get http://www.paymesurf.com:80/surf3.php?usrid=607 http/1.1+ #13 #10;

Httpstr:=httpstr+accept:image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg, Application/vnd.ms-powerpoint, Application/vnd.ms-excel, Application/msword, Application/x-shockwave-flash, */*+ #13 #10;

httpstr:=httpstr+accept-language:zh-cn+ #13 #10;

httpstr:=httpstr+user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; MyIE2;

. NET CLR 1.1.4322 + #13 #10;

httpstr:=httpstr+host:www.paymesurf.com+ #13 #10;

httpstr:=httpstr+proxy-connection:keep-alive+ #13 #10;

Above is a netizen's request content, but this cannot return the webpage content, the main problem is did not tell the server where is the end position. You need to add a + #13 #10 in the final position, so the server will know that this is the end.

2 How to know the Web page request completed, mainly through the fd_close to judge, when the page all returned, the server will automatically close this request, so you only know the current request to close the page has been downloaded.

3 below is my personal experience, if you want to write with the web communication software, it is best not to use the socket directly with the server to communicate, first of all, their own IE as a proxy mode, first look at how IE is through the agent software (this software you better write one, you can display the content of the request.) Work. Then you use your software to communicate with the server so you know where you usually go wrong.



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.