Windows phone 8 在windows phone 8中将POST参数传递到后台传输请求
如何在windows phone 8的后台传输上载请求中传递post参数?我必须将参数传递给服务器post参数名userfile,参数的文件名为song.m4aWindows phone 8 在windows phone 8中将POST参数传递到后台传输请求,windows-phone-8,upload,background-transfer,Windows Phone 8,Upload,Background Transfer,如何在windows phone 8的后台传输上载请求中传递post参数?我必须将参数传递给服务器post参数名userfile,参数的文件名为song.m4a // server to POST to string url = "myserver.com/path/to/my/post"; // HTTP web request var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Conten
// server to POST to
string url = "myserver.com/path/to/my/post";
// HTTP web request
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "text/plain; charset=utf-8";
httpWebRequest.Method = "POST";
// Write the request Asynchronously
using (var stream = await Task.Factory.FromAsync<Stream>(httpWebRequest.BeginGetRequestStream,
httpWebRequest.EndGetRequestStream, null))
{
//create some json string
string json = "{ \"my\" : \"json\" }";
// convert json to byte array
byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);
// Write the bytes to the stream
await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
}
试试这段代码,读一下答案