在过去的两天里,我一直在尝试使用 php 发布数据,在绝对肯定我的代码是合乎逻辑的之后,我放弃了尝试让它自己工作的尝试。
这是我的 C# 代码,
class SecureWeb
{
/*
* CONSTRUCTOR
*/
public SecureWeb()
{
//INITIALIZE
}
public bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
public string Post(string URI, NameValueCollection Message)
{
try
{
string result = null;
using (WebClient wc = new WebClient())
{
wc.Proxy = null;
wc.Credentials = CredentialCache.DefaultCredentials;
ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
byte[] bByte = wc.UploadValues(URI, (Message));
result = Encoding.UTF8.GetString(bByte);
}
return result;
}
catch (Exception) { }
return null;
}
}
这是我的 php 代码(是的,我尝试过使用简单的回显),
<?php
function getParams() {
if (!isset($_POST['db'])) {
return false;
}
if (!isset($_POST['user'])) {
return false;
}
return true;
}
if (!getParams()) {
echo('NULL_DATA');
exit();
}
else {
$user = $_POST['user'];
echo ($user);
exit();
}
?>
我收到一个 406 错误,声称我的请求是“不可接受的”。我也相当肯定手头的问题是我的服务器,我只是不确定需要修复或调整什么。