PHP POST方法进入RESTful Web服务

时间:2014-04-30 10:46:51

标签: php html web-services curl http-post

我想要做的简单事情是使用PHP POST到RESTful Web服务中。我已经能够使用PHP获取值,现在我想要POST到它。这是使用curl的PHP文件。

<?php
    $username = $_POST['username'];
    $password = $_POST['password'];

    $url = "http://localhost:8080/WMWS/webresources/entity.userregistration";

    $data = array('username' => $username, 'password' => $password);
    $initializeCurl = curl_init();
    curl_setopt($initializeCurl, CURLOPT_URL, $url);
    curl_setopt($initializeCurl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($initializeCurl, CURLOPT_POST, true);
    curl_setopt($initializeCurl, CURLOPT_POSTFIELDS, $data);
    $response = curl_exec($initializeCurl);
    curl_close($initializeCurl);
?>

我正在使用XAMPP,我在PHP.ini文件中启用了curl。每当我在HTML的表单输入中插入值并单击提交按钮时,它只返回浏览器上的PHP代码并且不执行任何插入操作。我怎么处理呢?

这是HTML文件:

<body>
    <form action = "posttoxml.php" method = "POST">
        <label for = "username">Username</label>
        <input type = "text" name = "username" />
        <label for = "password">Password</label>
        <input type = "password" name = "password" />
        <button id = "register" name = "register">Register</button>
    </form>
</body>

0 个答案:

没有答案