gpt4 book ai didi

c# - 来自 WP7 应用程序的帖子是一个空数组

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:09 24 4
gpt4 key购买 nike

我有以下代码用于在 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));
}

在 PHP 端,脚本只是执行以下操作:

var_dump($_POST);

这样做,我总是从服务器得到一个空数组。如果有任何不同,我将在模拟器而不是设备上运行它。我在这里做错了什么?

最佳答案

如果有人遇到这个问题正在寻找答案,那就是问题所在:

webClient.Headers["Content-Type"] = "text/xml";

应该改为:

webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";

关于c# - 来自 WP7 应用程序的帖子是一个空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com