Passing POST parameters to background transfer request in windows phone 8

266 views Asked by At

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)

1

There are 1 answers

0
Taras Kovalenko On
// 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