What about the data line delivered by request_by_socket?

Source: Internet
Author: User
What about the data row submitted by request_by_socket? $ Post_string & nbsp; = & nbsp; "app = socket & amp; version = beta & amp; username = ". $ userid. "& amp; pwd = ". $ userpwd. ""; $ re & nbsp; = & nbsp; request_by_s request_by_socket what about submitting data lines?
$ Post_string = "app = socket & version = beta & username =". $ userid. "& pwd =". $ userpwd ."";

$ Re = request_by_socket ('xinqq163. com', '/api/xinqq_login.php', $ post_string );
Echo $ re;



Function request_by_socket ($ remote_server, $ remote_path, $ post_string, $ port = 80, $ timeout = 30)
{
$ Socket = fsockopen ($ remote_server, $ port, $ errno, $ errstr, $ timeout );
If (! $ Socket) die ("$ errstr ($ errno )");

Fwrite ($ socket, "POST $ remote_path HTTP/1.0 \ r \ n ");
Fwrite ($ socket, "User-Agent: Socket Example \ r \ n ");
Fwrite ($ socket, "HOST: $ remote_server \ r \ n ");
Fwrite ($ socket, "Content-type: application/x-www-form-urlencoded \ r \ n ");
Fwrite ($ socket, "Content-length:". (strlen ($ post_string) + 8). '\ r \ n ');
Fwrite ($ socket, "Accept: */* \ r \ n ");
Fwrite ($ socket, "\ r \ n ");
Fwrite ($ socket, "mypost = $ post_string \ r \ n ");
Fwrite ($ socket, "\ r \ n ");
$ Header = "";
While ($ str = trim (fgets ($ socket, 4096 ))){
$ Header. = $ str;
}
$ Data = "";
While (! Feof ($ socket )){
$ Data. = fgets ($ socket, 4096 );
}
Return $ data;
}

Error message:
411 Length Required
------ Solution --------------------
Content-Length
------ Solution --------------------
411 Length Required: The server rejects the request without defining the Content-Length header. after a valid Content-Length header indicating the Length of the request message body is added, the client can submit the request again.
------ Solution --------------------
1. do not attach the username and password to them. use the same number of * numbers to see them ...... Change the password.
2. does HTTP/1.1 200 OK mean the returned result is correct?

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.