Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7 - POST form with an image
    primarykey
    data
    text
    <p>I need to send an image from the Windows Phone 7 to some e-mail addresses. I use this class to submit text values to a PHP script, wich parses data and sends a formatted e-mail to the addresses. The problem is that I can't figure out how to send an image to that script, to attach the image to the e-mail. The PHP script can be changed in any way. If I have an Image object, how can I change this class to allow sending images?</p> <pre><code>public class PostSubmitter { public string url { get; set; } public Dictionary&lt;string, string&gt; parameters { get; set; } public PostSubmitter() { } public void Submit() { // Prepare web request... HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest); } private void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; System.IO.Stream postStream = request.EndGetRequestStream(asynchronousResult); // Prepare Parameters String string parametersString = ""; foreach (KeyValuePair&lt;string, string&gt; parameter in parameters) { parametersString = parametersString + (parametersString != "" ? "&amp;" : "") + string.Format("{0}={1}", parameter.Key, parameter.Value); } byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(parametersString); // Write to the request stream. postStream.Write(byteArray, 0, parametersString.Length); postStream.Close(); // Start the asynchronous operation to get the response request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); } private void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseString = streamRead.ReadToEnd(); // Close the stream object streamResponse.Close(); streamRead.Close(); // Release the HttpWebResponse response.Close(); //Action&lt;string&gt; act = new Action&lt;string&gt;(DisplayResponse); //this.Dispatcher.BeginInvoke(act, responseString); } </code></pre> <p>I use the class in this way:</p> <pre><code>Dictionary&lt;string, string&gt; data = new Dictionary&lt;string, string&gt;() { {"nom", nom.Text}, {"cognoms", cognoms.Text}, {"email", email.Text}, {"telefon", telefon.Text} }; PostSubmitter post = new PostSubmitter() { url = "http://example.com/parserscript.php", parameters = data }; post.Submit(); </code></pre> <p>Thank you very much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload