1

我想将 Windows Phone 与远程服务器连接。

我试图连接当时发生以下错误。如何解决它。

System.Windows.ni.dll 中发生了“System.Net.WebException”类型的异常,并且在托管/本机边界之前未处理

这里我的代码

C# 代码

进度指示器编;

    private void btnLogin_Click(System.Object sender, System.Windows.RoutedEventArgs e)
    {
        try
        {
            string url = "http://192.168.2.112/check_login/check.php";
            //string url = "http://localhost/sam.php";
            Uri uri = new Uri(url, UriKind.Absolute);

            StringBuilder postData = new StringBuilder();
            postData.AppendFormat("{0}={1}", "sUsername", HttpUtility.UrlEncode(this.txtUsername.Text));
            postData.AppendFormat("&{0}={1}", "sPassword", HttpUtility.UrlEncode(this.txtPassword.Password.ToString()));

            WebClient client = default(WebClient);
            client = new WebClient();
            client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();

            client.UploadStringCompleted += client_UploadStringCompleted;
            client.UploadProgressChanged += client_UploadProgressChanged;

            client.UploadStringAsync(uri, "POST", postData.ToString());
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        prog = new ProgressIndicator();
        prog.IsIndeterminate = true;
        prog.IsVisible = true;
        prog.Text = "Loading....";
        SystemTray.SetProgressIndicator(this, prog);

    }

   private void client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
    {
        //Me.txtResult.Text = "Uploading.... " & e.ProgressPercentage & "%"
    }

    private void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        if (e.Cancelled == false & e.Error == null)
        {
            prog.IsVisible = false;
            MessageBox.Show(e.Result.ToString());
        }
    }

PHP 代码

  <?php
      $hostname_localhost ="localhost";
      $database_localhost ="androidlogin";
      $username_localhost ="root";
      $password_localhost ="";
      $localhost=mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
     or
     trigger_error(mysql_error(),E_USER_ERROR);

     mysql_select_db($database_localhost, $localhost);

     $username = $_POST['username'];
     $password = $_POST['password'];
   $query_search = "select * from user where username = '".$username."' AND password = '".$password. "'";
     $query_exec = mysql_query($query_search) or die(mysql_error());
     $rows = mysql_num_rows($query_exec);
     //echo $rows;
     if($rows == 0) { 
     echo "No Such User Found"; 
 }
else  {
echo "User Found"; 
  }
 ?>

请帮我。提前致谢。

4

0 回答 0