Но соединение не удалось:
System.Net.WebException: Ошибка: ConnectFailure (Соединение отклонено)
Моя страница в xaml:
Код: Выделить всё
Код: Выделить всё
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace fullApp
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
pass.IsPassword = true;
}
void Register_Clicked(object sender, EventArgs e)
{
PostJson("http://localhost:3308/test/API/register_user.php", new users
{
username = user.Text,
password = pass.Text,
PhoneNumber = phone.Text,
Governorate = gover.Text,
City = city.Text,
Street = street.Text
});
void PostJson(string uri, users postParameters)
{
string postData = JsonConvert.SerializeObject(postParameters);
byte[] bytes = Encoding.UTF8.GetBytes(postData);
var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.ContentType = "text/xml";
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Count());
}
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}", httpWebResponse.StatusCode);
throw new ApplicationException(message);
}
}
}
}
public class users
{
public string username { get; set; }
public string password { get; set; }
public string PhoneNumber { get; set; }
public string Governorate { get; set; }
public string City { get; set; }
public string Street { get; set; }
}
}
Код: Выделить всё
using (Stream requestStream = httpWebRequest.GetRequestStream())

Страница регистрации

После входа или регистрации
[img]https:// i.sstatic.net/UJNgH.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/615 ... on-refused