Note that there are some explanatory texts on larger screens.

plurals
  1. POPush an variable into a method
    primarykey
    data
    text
    <p>I have an httpWebRequest to access an XML and save it locally then read it and show it to the screen. Problem is, i have to do this for more than one "pivot item", and the method that saves the xml is </p> <pre><code>private static void GetResponseCallback(IAsyncResult asynchronousResult) </code></pre> <p>and doesn't support adding a new variable to it so i can dynamically name the xml ("tmp"+xmlName+".xml") . </p> <p>So the question is: <strong>How do i push a variable in the xml name ?</strong></p> <pre><code>public class HttpWebReqMethod { public void httpRequestMethod (string url, string xmlName) { HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.ContentType = "text/xml"; httpRequest.Method = "POST"; httpRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), httpRequest); } private static void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest httpRequest = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation Stream postStream = httpRequest.EndGetRequestStream(asynchronousResult); string postData = ""; // Convert the string into a byte array. byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Write to the request stream. postStream.Write(byteArray, 0, postData.Length); postStream.Close(); // Start the asynchronous operation to get the response httpRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), httpRequest); } private static void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest httpRequest = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation HttpWebResponse response = (HttpWebResponse)httpRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseStream = streamRead.ReadToEnd(); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var istream = new IsolatedStorageFileStream(@"tmp" + xmlName + ".xml", FileMode.OpenOrCreate, store)) { using (var sw = new StreamWriter(istream)) { sw.Write(responseStream); } } } // Close the stream object streamResponse.Close(); streamRead.Close(); // Release the HttpWebResponse response.Close(); } </code></pre>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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