Php 如何通过url向类发送帖子?

Php 如何通过url向类发送帖子?,php,web-services,Php,Web Services,我想编写一个简单的PHP代码,将数据发送到URL中的类。 我已经编写了代码,但它只用于将数据直接发送到URL。 如何编写此代码? 类名为“sendmsg” <?php $url = 'https://thxmain.cellmobilen.net:443/Charg/service/ChargingMobile'; $data = array( 'username' => '?', 'password' => '?', 'domain' => '?', 'ch

我想编写一个简单的
PHP
代码,将数据发送到URL中的类。 我已经编写了代码,但它只用于将数据直接发送到URL。 如何编写此代码? 类名为“sendmsg”

<?php

$url = 'https://thxmain.cellmobilen.net:443/Charg/service/ChargingMobile';

$data = array(
 'username' => '?',
 'password' => '?',
 'domain' => '?',
 'channel' => '?',
 'mobilenum' => '?',
 'serviceId' => '?',
 'price' => '?',
 'trackingId' => '?'
);

$options = array(
   'http' => array(
       'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
       'method'  => 'POST',
       'content' => http_build_query($data)
   )
);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

if ($result !== FALSE) {
 var_dump($result);
}else{
 print( "Code is wrong" );
}

?>




对不起,我真的不明白你的问题是什么?你发布的代码有效吗?我是否正确地理解,在某个地方存在一个您自己编写的类,名为
sendmsg
?你想调用这个类,而不是post请求?我想通过这个url将数据发送到sendmsg类。这段代码的问题是它不向类发送数据。请帮助我将数据发送到sendmsg类。