如何使用yii框架将数据发送到特定端口和ip ?我想发送一个字符串到特定的ip。
使用php,你可以使用GET或POST或任何你喜欢的方法发送数据,使用这个方法:
<?php
// change this to your own values
$ip = '127.0.0.1';
$port = 80;
$location = '';
$url = "http://$ip:$port/$location";
// define the data you want to send
$params = http_build_query(
array(
'name1' => $value1,
'name2' => $value2,
// ...
)
);
// set the method to send the data
$opts = array('http' =>
array(
'method' => 'GET', // or POST or PUT or DELETE
'content' => $params,
'header' => 'Content-Type: application/x-www-form-urlencoded'r'n'
)
);
$context = stream_context_create($opts); //build the http context
// send the data and capture the response
$response = file_get_contents($url.$params, false, $context);