Im kind of stuck with a HttpWebRequest while sending post values and i dont know what the problem is.
Hopefully anyone is able to help me with this.
this is my code
private async void loggingIn(string url, string postdata)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
try
{
var request = WebRequest.Create(new Uri(url)) as HttpWebRequest;
request.Method = "POST";
byte[] data = Encoding.UTF8.GetBytes(postdata);
request.ContentLength = data.Length;
using (var requestStream = await Task<Stream>.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, request))
{
await requestStream.WriteAsync(data, 0, data.Length);
}
WebResponse responseObject = await Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, request);
var responseStream = responseObject.GetResponseStream();
var sr = new StreamReader(responseStream);
string received = await sr.ReadToEndAsync();
MessageBox.Show(received);
}
catch
{
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string url = "localhost/test.php";
string password = passwordBoxLogin.Password;
string username = usernameBoxLogin.Text;
string postdata = "password=" + password +"&username="+username;
loggingIn(url,postdata);
}
The problem is that my server does not receive any values from the POST request.
but i do get a response from the server.
this is what i use to check the code on my php server
<?php
echo $_POST['username'];
echo"-";
echo $_POST['password'];
?>
the only thing i get returned is the -
Thanks in advance for helping me out :)
It just started working without anychanges.
For now case closed!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…