php post запрос



Post запрос php

Автор Dzuravskiy-pavel задал вопрос в разделе Другие языки и технологии

php отправка post запросов и получил лучший ответ

Ответ от Ewe 2e¶ CoЛнЫшКоcBeTиТоЧеНЬяРкО*[гуру]
function PostRequest($url, $referer, $_data) {
// convert variables array to string:
$data = array();
while(list($n,$v) = each($_data)){
$data[] = "$n=$v";
}
$data = implode('&', $data);
// format --> test1=a&test2=b etc.
// parse the given URL
$url = parse_url($url);
if ($url['scheme'] != 'http') {
die('Only HTTP request are supported !');
}
// extract host and path:
$host = $url['host'];
$path = $url['path'];
// open a socket connection on port 80
$fp = fsockopen($host, 80);
// send the request headers:
fputs($fp, "POST $path HTTP/1.1
");
fputs($fp, "Host: $host
");
fputs($fp, "Referer: $referer
");
fputs($fp, "Content-type: application/x-www-form-urlencoded
");
fputs($fp, "Content-length: ". strlen($data) ."
");
fputs($fp, "Connection: close
");
fputs($fp, $data);
$result = '';
while(!feof($fp)) {
// receive the results of the request
$result .= fgets($fp, 128);
}
// close the socket connection:
fclose($fp);
// split the result header from the content
$result = explode("
", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
// return as array:
return array($header, $content);
}
/*
** The example:
*/
// submit these variables to the server:
$data = array(
'test' => 'foobar',
'okay' => 'yes',
'number' => 2
);
// send a request to example.com (referer = jonasjohn.de)
list($header, $content) = PostRequest(
"",
"",
$data
);
// print the result of the whole request:
print $content;
// print $header; --> prints the headersИсточник: ссылка

Ответ от Demoniqus[гуру]
Подключи файл с другого сервера к своему сценарию и запроси функцию на том серваке, передав ей необходимые параметры (если она понимает такие параметры) . Если эта функция что-либо возвращает, то она тебе вернет какой-то ответ.

Ответ от 3 ответа[гуру]
Привет! Вот подборка тем с похожими вопросами и ответами на Ваш вопрос: php отправка post запросов
 

Ответить на вопрос:

Имя*

E-mail:*

Текст ответа:*
Проверочный код(введите 22):*