PHP POST Request garbled problem
Use the most Earth template in the POST request source code as follows
static public Function DoPost ($url, $post _data=array ()) {
$url 2 = Parse_url ($url);
$url 2["path"] = ($url 2["path"] = = ""? " /": $url 2[" path "]);
$url 2["port"] = ($url 2["port"] = = ""? : $url 2["Port"]);
$host _ip = @gethostbyname ($url 2["host"]);
$fsock _timeout = 2; 2 Second
if ($fsock = Fsockopen ($host _ip, $url 2[' Port '], $errno, $errstr, $fsock _timeout)) < 0) {
return false;
}
$request = $url 2["path"]. ($url 2["Query"]? "?" . $url 2["Query"]: "");
$post _data2 = http_build_query ($post _data);
$post _data2=urldecode ($post _data2);
$in = "POST". $request. "Http/1.0\r\n";
$in. = "Accept: */*\r\n";
$in. = "Host:". $url 2["Host"]. "\ r \ n";
$in. = "user-agent:lowell-agent\r\n";
$in. = "content-type:application/x-www-form-urlencoded\r\n";
$in. = "Content-length:". strlen ($post _data2). "\ r \ n";
$in. = "connection:close\r\n\r\n";
$in. = $post _data2. "\r\n\r\n";
unset ($post _data2);
if (! @fwrite ($fsock, $in, strlen ($in))) {
Fclose ($fsock);
return false;
}
Return self::gethttpcontent ($fsock);
}
Static Private Function Gethttpcontent ($fsock =null) {
$out = null;
while ($buff = @fgets ($fsock, 2048)) {
$out. = $buff;
}
Fclose ($fsock);
$pos = Strpos ($out, "\r\n\r\n");
$head = substr ($out, 0, $pos); HTTP Head
$status = substr ($head, 0, Strpos ($head, "\ r \ n")); HTTP status Line
$body = substr ($out, $pos + 4, strlen ($out)-($pos + 4));//page body
if (Preg_match ("/^http\/\d\.\d\s ([\d]+) \s.*$/", $status, $matches)) {
if (Intval ($matches [1])/100 = = 2) {
return $body;
}else{
return false;
}
}else{
return false;
}
}
The implementation of the HTTP text message is sent because the operator did not urldecode I can only think of the parameters of the original text request sent to the phone text message is garbled I contact PHP also soon want to ask you have any way to solve garbled problem.
It is not possible to request HTTP by other means. PHP garbled