PHP中的Encoding.ASCII.GetBytes

时间:2011-07-28 08:48:20

标签: php asp.net .net

我试图在php中复制以下内容虽然我被困在Encoding.ASCII.GetBytes(paramList)

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
string paramList = "paramList=ThruDate_" + thruDate.ToString() + "|OwnerLevel_" + ownerLevel;
Stream stream = req.GetRequestStream();
byte[] bytes = Encoding.ASCII.GetBytes(paramList);
stream.Write(bytes, 0, bytes.Length);
stream.Close();

1 个答案:

答案 0 :(得分:0)

使用php时,不需要获取一个字节数组就可以将POST数据发送到某个http服务器。

$postdata = "something=something";
$ctx = stream_context_create(array(
    'http'=>array(
        'method'=>'POST'
        'content'=>$postdata,
        'header' => 'Content-type: application/x-www-form-urlencoded'
    )
));
$responsedata = file_get_contents('http://...', false, $ctx);

另见:
http://docs.php.net/file_get_contents
http://docs.php.net/context.http