0

我需要通过使用 PHP 的 HTTP 请求使用 get 变量发送 API 请求。

格式类似于:

https:"www.thirdpartyurl.com"/Request.ashx?command=_&username= _&password=______&customer=__&customerpassword=___

其中 1. 命令 = 创建客户

  1. 用户名 = 我的用户名

  2. 密码 = 我的帐户密码

  3. 客户=客户用户名(他填写的表格)

  4. 客户密码 = 客户密码(在表格中填写)

请在下面查看我的 HTML 文件:

<html>
<head>
<meta charset="utf-8">
<title>Sample request</title>
</head>
<body>
<form action="operations.php" method="post">
<p>userid
<input id='textbox1' type="text" name="custuname" value="" placeholder="Enter User name">
</p>
<p>password
<input id='textbox1' type="text" name="custpwd" value="" placeholder="Enter User name">
</p>
<input type="submit" name="Create Account" id="create_account" value="Create">
</form>
</body>
</html>

我的 php 文件是:

<?php
$baseurl = "www.thirdpartyurl.com";
$username = "xxxxx";
$pw = "xxxx";
$customer = "$_POST(custuname)";
$customerpw = "$_POST(custpwd);
&tariffrate=4;
$params = array("command"=>"createcustomer", "username"=>$username, "password"=>$pw, 
"customer"=>$customer,"customerpassword"=>$customerpw,"tariffrate"=>&tariffrate);
$link = $baseurl . '?' . http_build_query($params);
?>

当单击提交按钮而不是创建帐户时,它会在浏览器中显示 PHP 代码上方。请帮助我。

4

3 回答 3

0

首先检查您是否在服务器上托管了您的 php 文件,因为如果脚本不正确,它必须给您一个错误,而不是显示相同的书面脚本。这表明您没有在 wamp、xammp 或 tom cat 等服务器上托管您的 php 文件。

于 2014-03-03T12:46:27.673 回答
0

应该

$customer = $_POST['custuname'];
$customerpw = $_POST['custpwd'];

代替

$customer = "$_POST(custuname)";
$customerpw = "$_POST(custpwd); //<----quotes not closed
于 2013-11-14T06:58:13.900 回答
0

你可以试试这个,&tariffrate=4;应该 $tariffrate=4;添加curl发送api请求

HTML:

<html>
<head>
<meta charset="utf-8">
<title>Sample request</title>
</head>
    <body>
        <form action="operations.php" method="post">
        <p>userid
        <input id='textbox1' type="text" name="custuname" value="" placeholder="Enter User name">
        </p>
        <p>password
        <input id='textbox1' type="text" name="custpwd" value="" placeholder="Enter User name">
        </p>
        <input type="submit" name="CreateAccount" id="create_account" value="Create">
        </form>
    </body>
</html>

PHP

    if(isset($_POST['CreateAccount'])){
        $baseurl = "www.thirdpartyurl.com";
        $username = "xxxxx";
        $pw = "xxxx";
        $customer = $_POST['custuname'];
        $customerpw = $_POST['custpwd'];
        $tariffrate=4;
        $params = array("command"=>"createcustomer", "username"=>$username, "password"=>$pw, 
        "customer"=>$customer,"customerpassword"=>$customerpw,"tariffrate"=>$tariffrate);
        $link = $baseurl . '?' . http_build_query($params);



             $ch = curl_init();              
             // Set query data here with the URL
             curl_setopt($ch, CURLOPT_URL, $link);

             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, '3');
             $content = trim(curl_exec($ch));
             curl_close($ch);
             print $content;

     }
  ?>
于 2013-11-14T07:00:21.540 回答