[英]I need to send API request using get variables via HTTP requests using PHP
I need to send API request using get variables via HTTP requests using PHP. 我需要使用PHP通过HTTP请求使用get变量发送API请求。
Format is some thing like: 格式类似于:
https:"www.thirdpartyurl.com"/Request.ashx?command=_&username= _&password=______&customer=__&customerpassword=___
Where 1. command = create customer 其中1.命令=创建客户
username = my username 用户名=我的用户名
password = my account password 密码=我的帐户密码
customer=customer user name(which he fills in the form) customer =客户用户名(他填写表格)
Customer password = customer password(as filed in the form) 客户密码=客户密码(在表格中填写)
Please have a look below for my HTML file : 请在下面查看我的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>
My php file is : 我的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);
?>
When clicked on submit button instead of creating account it is showing me above PHP code in the browser. 当单击提交按钮而不是创建帐户时,它在浏览器中的PHP代码上方显示给我。 Kindly help me on this.
请帮助我。
Should be 应该
$customer = $_POST['custuname'];
$customerpw = $_POST['custpwd'];
instead of 代替
$customer = "$_POST(custuname)";
$customerpw = "$_POST(custpwd); //<----quotes not closed
Can you try this, &tariffrate=4;
您能尝试一下吗,
&tariffrate=4;
should be $tariffrate=4;
应该是
$tariffrate=4;
Added curl
to send api request 添加了
curl
以发送api请求
HTML: 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 : 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;
}
?>
First check whether you have hosted your php file on a server or not because it must give you an error if the script is incorrect instead of showing the same written script. 首先检查您是否将php文件托管在服务器上,因为如果脚本不正确,它必须给您一个错误,而不是显示相同的书面脚本。 that indicates that you have not hosted your php file on a server like wamp, xammp or a tom cat etc.
这表明您尚未将php文件托管在wamp,xammp或tom cat等服务器上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.