【发布时间】:2018-08-18 14:09:52
【问题描述】:
我想使用 HTTP Web POST 将数据从我的表单插入到我的服务器。我的代码在下面,我无法获取 JObject json 的值并将其发送到我的 php 代码中。
var caf = entCafNo.Text;
string url = "http://192.168.120.9:7777/TBS/mobile-request.php?Host=" + Constants.hostname + "&Database=" + Constants.database + "&Request=SendCaf";
string contentType = "application/json";
JObject json = new JObject
{
{ "CAF", caf }
};
HttpClient client = new HttpClient();
var response = await client.PostAsync(url, new StringContent(json.ToString(), Encoding.UTF8, contentType));
PHP 代码:
$request = $_GET["Request"];
if($request == "SendCaf"){
$caf = $_POST["CAF"];
$sql = "INSERT INTO tblCaf(CAFNo)
VALUES('$caf)";
mysqli_query ($conn, $sql);
}
【问题讨论】:
-
您的脚本对SQL Injection Attack 甚至if you are escaping inputs, its not safe! 都是开放的,在
MYSQLI_或PDOAPI 中使用prepared parameterized statements -
尝试添加
print_r($_POST); print_r($_GET);以查看发送到 PHP 的内容 -
@RiggsFolly 我的 php 代码没有获取数据
-
@RiggsFolly 我修复了我的链接我忘记了链接中的 php 文件我如何获取数据
{ "CAF", caf }, { "CAF2", caf2 } -
有了这个错误,我猜(不知道 xamarin)该 URL 是错误的
标签: php json xamarin xamarin.forms httpclient