How to pass post parameters in background transfer upload request for windows phone 8? I have to pass parameter to the server (post parameter name "userfile" with a file name "song.m4a" for the parameter)
Asked
Active
Viewed 253 times
1 Answers
0
// 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);
}
Try this code and read this answer Http Post for Windows Phone 8

Community
- 1
- 1

Taras Kovalenko
- 2,323
- 3
- 24
- 49