I have the following code for handling a simple post under WP7:
private void goto_login(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
webClient.Headers["Content-Type"] = "text/xml";
var uri = new Uri("http://example.com/wp_login", UriKind.Absolute);
StringBuilder postData = new StringBuilder();
postData.AppendFormat("{0}={1}", "username", HttpUtility.UrlEncode(username_box.Text));
postData.AppendFormat("&{0}={1}", "password", HttpUtility.UrlEncode(password_box.Password));
webClient.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
webClient.UploadProgressChanged += webClient_UploadProgressChanged;
webClient.UploadStringAsync(uri, "POST", postData.ToString());
}
void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
Debug.WriteLine("result: "+e.Result);
}
void webClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
Debug.WriteLine(string.Format("Progress: {0} ", e.ProgressPercentage));
}
On the PHP side, the script simply does this:
var_dump($_POST);
Doing this, I always end up with an empty array from the server. If it makes any difference, I’m running it on the emulator instead of a device. What am I doing wrong here?
If anyone happens by this question looking for an answer, this was the problem:
Should be changed to: