0

我的 C# 代码有问题,该代码从登录表单发布数据以在 PHP 页面上进行验证。

在我的开发页面上,它工作正常,但是当我切换到生产页面时,它停止工作。(两个网页位于同一台服务器上)。

我的登录页面(开发)如下所示:

$user = DB_Login($_POST["username"], $_POST["password"]);
if (!is_null($user))
{
SetLoginCookies($user["userID"], $user["sessionID"]);
echo "valid";
}
else
echo "invalid";

我的生产页面如下所示:

$responseArray = DB_Login($_POST["username"], $_POST["password"]);

if (is_null($responseArray))
{
    die("invalid");
}

它非常相似,但我不明白为什么我的生产页面从不接收 POST 变量,它总是死掉。

我的 C# 代码(其中任一页面)如下所示:

private void Login_Click(object sender, RoutedEventArgs e)
    {
        string sendData = "";
        Uri site = new Uri("site");
        WebClient wc = new WebClient();
        wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
        sendData += "username=" + usrname.Text;
        sendData += "&password=" + pword.Password;
        wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString();
        wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
        wc.UploadStringAsync(site, "POST", sendData);
    }

    private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        if (e.Result.Equals("invalid"))
        {
            return;
        }
        else
        {
            MessageBox.Show(e.Result.ToString());

            //Navigate to next page
            NavigationService.Navigate(new Uri("/ControlPanel.xaml", UriKind.Relative));
        }
    }

有任何想法吗?

更新:

DB_Login 函数如下所示:

function DB_Login($username, $password)
{
$password = md5($password);
$username = mysql_escape_string($username);

$request = DB_ExecuteQuery("SELECT userID, isAdmin
    FROM accounts
    WHERE username = '$username' AND password = '$password'");
if ($request->num_rows == 0)
    return NULL;

$requestArray = $request->fetch_array();

$response = array("userID" => $requestArray["userID"]);
$response["sessionID"] = mysql_escape_string(generateGuid());
$response["isAdmin"] = $requestArray["isAdmin"];

DB_ExecuteQuery("UPDATE accounts
    SET sessionID = '". $response['sessionID'] ."'
    WHERE userID = ". $response['userID']);

DB_SetLastLogin($requestArray['userID']);

return $response;
}

var_dump($_POST["username"], $_POST["password"]) 的结果是 NULL 和 NULL。

更新2:

$print_r($_SERVER) 的结果:

Array (
  [SCRIPT_URL] => /phone/windowsphone/driverDetails.php
  [SCRIPT_URI] => https://www.xxxxx.com/phone/windowsphone/driverDetails.php 
  [MvCONFIG_FLAGS_SECURITY] => 15
  [MvCONFIG_DIR_MIVA] => /home/sites/home/miva
  [MvCONFIG_DIR_DATA] => /home/sites/home/mivadata
  [MvCONFIG_DIR_BUILTIN] => /home/miva/builtins
  [MvCONFIG_DIR_CA] => /home/miva/certs
  [MvCONFIG_DIR_BUILTIN] => /home/miva/builtins
  [MvCONFIG_DIR_CA] => /home/miva/certs
  [MvCONFIG_SSL_CRYPTO] => /lib/libcrypto.so.4
  [MvCONFIG_SSL_OPENSSL] => /lib/libssl.so.4
  [MvCONFIG_DATABASE_MivaSQL] => /home/miva/databases/mivasql.so
  [MvCONFIG_DATABASE_mysql] => /home/miva/databases/mysql.so
  [MvCONFIG_COMMERCE_AuthorizeNet] => /home/miva/commerce/authnet-v5.06-linux_glibc2.so
  [MvCONFIG_COMMERCE_CyberCash] => /home/miva/commerce/cybercash_de-v5.03-linux_glibc2.so
  [MvCONFIG_COMMERCE_ICS2] => /home/miva/commerce/ics2-v5.06-linux_glibc2.so
  [MvCONFIG_COMMERCE_LinkPoint] => /home/miva/commerce/linkpoint-v5.06-linux_glibc2.so
  [MvCONFIG_COMMERCE_UPSRSS] => /home/miva/commerce/upsrss-v5.03-linux_glibc2.so
  [MvCONFIG_LIBRARY] => /home/miva/config/env.so
  [HTTPS] => on
  [HTTP_HOST] => www.xxxxx.com
  [HTTP_CONNECTION] => keep-alive
  [HTTP_CACHE_CONTROL] => max-age=0
  [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
  [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
  [HTTP_ACCEPT_LANGUAGE] => en-GB,en-US;q=0.8,en;q=0.6
  [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
  [HTTP_COOKIE] => ow-autologin=0; ow-loginname=whaxi; ow-default_logindomain=www.xxxxx.com; ow-httpcompress=1
  [PATH] => /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
  [SERVER_SIGNATURE] => Apache Server at www.xxxxx.com Port 443
  [SERVER_SOFTWARE] => Apache
  [SERVER_NAME] => www.xxxxx.com
  [SERVER_ADDR] => 11.22.33.44
  [SERVER_PORT] => 443
  [REMOTE_ADDR] => 44.33.22.11
  [DOCUMENT_ROOT] => /home/.sites/28/site1/web
  [SERVER_ADMIN] => admin
  [SCRIPT_FILENAME] => /home/.sites/28/site1/web/phone/windowsphone/driverDetails.php
  [REMOTE_PORT] => 16199
  [GATEWAY_INTERFACE] => CGI/1.1
  [SERVER_PROTOCOL] => HTTP/1.1
  [REQUEST_METHOD] => GET
  [QUERY_STRING] =>
  [REQUEST_URI] => /phone/windowsphone/driverDetails.php
  [SCRIPT_NAME] => /phone/windowsphone/driverDetails.php
  [PHP_SELF] => /phone/windowsphone/driverDetails.php
  [REQUEST_TIME] => 1343076397
  [argv] => Array ( )
  [argc] => 0
)
4

3 回答 3

1
UploadStringAsync

函数将字符串作为 RAW 数据发送,在 $_POST 数组中看不到,php 代码使用

file_get_contents('php://input')

接收它,或者在 C# 中使用

NameValueCollection reqparm = new NameValueCollection();
reqparm.Add("username", "asd");
reqparm.Add("pass", "smthg");
...
wc.UploadValues(this.url, "POST", this.reqparm);
于 2014-11-25T11:27:00.330 回答
0

嗯,我认为您应该在标题中获取 POST 方法,而不是获取 GET 方法。

于 2012-07-23T21:07:00.287 回答
0

尝试寻找

method="post"

在您的<form>标签或其他任何内容中。如果你看到类似...

method="get"

... 那是你的问题。更改发布方式。

于 2014-05-29T21:04:52.217 回答