Php 如何通过POST方法调用web服务

Php 如何通过POST方法调用web服务,php,Php,我在学习编程。我的XAMPP中有一个php文件,该文件用于将数据插入数据库 我想使用post方法调用php文件并执行sql字符串 我的PHP文件: <?php $DB_HostName = "localhost"; // ten host $DB_Name = "QM_TEST"; $DB_User = "root"; $DB_Pass = ""; $DB_Table = "Customer";

我在学习编程。我的XAMPP中有一个php文件,该文件用于将数据插入数据库

我想使用post方法调用php文件并执行sql字符串

我的PHP文件:

<?php
$DB_HostName = "localhost"; // ten host
$DB_Name = "QM_TEST";           
$DB_User = "root";          
$DB_Pass = "";              
$DB_Table = "Customer";             

$name = $_GET[@"name"];
$address = $_GET[@"address"];

$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 
mysql_select_db($DB_Name,$con) or die(mysql_error()); 
$sql = "insert into $DB_Table (name, address) values('$name','$address');";
$res = mysql_query($sql,$con) or die(mysql_error());

mysql_close($con);
if ($res) {
    echo "success";
}else{
    echo "faild";
}// end else
?>

如果不想使用cURL,可以使用
[stream\u context\u create()][1]
来完成

下面是一个例子:

    $url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');

// use key 'http' even if you send the request to https://...
$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);

var_dump($result);

还有一个类似的问题。

这与OSX或Cocoa有什么关系?它与OSX无关,也不清楚您遇到了什么问题。