Eduardo Fuerte
asked on
Could you point a way on how to call a PHP file with parameters from inside a C# code?
Hi Experts
Could you point a way on how to call a PHP file with parameters from inside a C# code?
It isn't needed to receive any value from PHP .
(WF project)
Thanks in advance.
Could you point a way on how to call a PHP file with parameters from inside a C# code?
It isn't needed to receive any value from PHP .
(WF project)
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
We'd really need to know what the PHP code is doing/expecting. Prakash's code works for a GET request, but it will not work if the PHP is expecting a POST. Can you expand on the PHP code?
Could you point a way on how to call a PHP file with parameters from inside a C# code?
It isn't needed to receive any value from PHP .
@käµfm³d, Thanks for comment, but as @Eduardo has already mentioned that parameter will be passed to it, and it is not needed to receive any value from PHP!
You can send form-data in query string and it will work same as POST method in PHP! (I guess), so it won't be a problem
So my solution will work for this case!
ASKER
Hi
@Prakash Samariya
I guess your solution is near to work
C# code:
PHP Code (registra.php):
I don't know why the parameters sent is received as "blank values" accordingly with
(the third line is correct, obtained from another technology system)
Table structure
Any suggestions?
@Prakash Samariya
I guess your solution is near to work
C# code:
private void bttnCLOSE_Click(object sender, System.EventArgs e)
{
using (var client = new WebClient())
{
var parameter1 = "Bibliotecas";
var parameter2 = "0";
var parameter3 = "TRIAL";
var result = client.DownloadString(string.Format("http://www.mysite.com.br/registra.php?parameter1={0}¶meter2={1}¶meter2={2}", parameter1, parameter2, parameter3));
}
this.Close();
}
PHP Code (registra.php):
<?php
$sistema = $_POST['sistema'];
$key = $_POST['key'];
$client = $_POST['client'];
// Connect to server and select database.
mysql_connect("$host", "$usermysql", "$passmysql")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$dia = date("d/m/Y H:i:s");
$sql = "INSERT INTO XXXX_login(sistema, casa, cpfc, dia) VALUES ('%s','%s', '%s','%s');";
// echo $sql;
$comando = sprintf($sql, $sistema, $client, $key, $dia);
$result=mysql_query($comando);
?>
I don't know why the parameters sent is received as "blank values" accordingly with
(the third line is correct, obtained from another technology system)
Table structure
Any suggestions?
ASKER
Changing C# code to
And adapting the PHP code to:
It works fine. Maybe something else must be considered.
var result = client.DownloadString(string.Format("http://www.mysite.com.br/registra.php?sistema=BIBLIOTECAS&key=0&client=TRIAL"));
And adapting the PHP code to:
$sistema = $_GET['sistema'];
$key = $_GET['key'];
$client = $_GET['client'];
It works fine. Maybe something else must be considered.
var result = client.DownloadString(string.Format("http://www.mysite.com.br/registra.php?parameter1={0}&key={1}¶meter2={2}", parameter1, parameter2, parameter3));
Replace with below line
var result = client.DownloadString(string.Format("http://www.mysite.com.br/registra.php?sistema={0}¶meter2={1}&client={2}", parameter1, parameter2, parameter3));
@Prakash
As you can plainly see in the PHP, it's expecting POST parameters:
e.g.
You can send form-data in query string and it will work same as POST method in PHP!You cannot possibly say that without seeing the code; otherwise, you're just speculating. It all depends on how the PHP is written. If it is expecting POST data, then it won't look in the querystring. The HTTP spec doesn't forbid querystring parameter on POSTs, but generally speaking your "parameters" are in the data. Just because OP says "passed", it does not implicitly mean "passed via querystring."
As you can plainly see in the PHP, it's expecting POST parameters:
e.g.
$_POST['sistema'];
ASKER
Sorry.... coding correctly
Works fine!
var result = client.DownloadString(string.Format("http://www.mysite.com.br/registra.php?sistema={0}&key={1}&client={2}", parameter1, parameter2, parameter3));
Works fine!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Our messages crossed... same meaning!
ASKER
@käµfm³d 👽
In my case it's not necessary to use POST.
In my case it's not necessary to use POST.
ASKER
Thanks for help!