1

我正在使用 Visual Studio Express 2012 RC 为 Windows 8 设计我的 Metro 风格应用程序。

过去,我为 windows phone 开发了一个应用程序,我曾经在其中webclient.uploadstringasync将字符串数据发布到服务器。但由于webclientWindows 8 不存在,我正在寻找它的替代方案。

我尝试使用httpclient.postasync但它不起作用(不知道为什么)。

谁能建议我该怎么做。请解释您建议的任何方法并尝试举例说明。我是 C# 的初学者,所以任何帮助都会起作用。谢谢

这是我使用httpclient.postasync但没有工作的代码示例(不知道为什么)。

HttpClient data=new HttpClient();
HttpContent post;
async private void buttonupdate_Click(object sender, RoutedEventArgs e)
{
    post=new StringContent("I put the string here which is to be posted");
    await data.PostAsync(URI,post);  
}
4

2 回答 2

1
HttpContent stringContent = new StringContent("Put Your Data Here");
stringContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
stringContent.Headers.ContentLength = uriString.Length;
stringContent.Headers.ContentEncoding.Add("UTF-8");
于 2012-07-16T14:45:25.260 回答
0

请查看 Windows 8 的 BackgroundUploader 类,它提供了可能有助于实现您的要求的重载方法

MSDN

于 2012-07-10T19:29:29.087 回答