public void doSend() { StringBuilder completeUrl = new StringBuilder(urlAddress); objRequest = (HttpWebRequest)WebRequest.Create(urlAddress.ToString()); objRequest.ContentType = "application/x-www-form-urlencoded"; objRequest.Method = "POST"; objRequest.Headers["SOAPAction"] = "http://tempuri.org/Register"; myRequestData = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> <soap:Body> <authenticate xmlns=""http://tempuri.org/""> <platformTuru>iPhone</platformTuru> <MusteriNo>NULL</MusteriNo> <request> <username>{0}</username> <getAdslPassword>1</getAdslPassword> <password>{1}</password> </request> </authenticate> </soap:Body> </soap:Envelope>", username.Text, password.Password); objRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), objRequest); //HttpWebRequestExtensions.GetRequestStream(objRequest); //HttpWebRequestExtensions.GetResponse(objRequest); } private static void GetRequestStreamCallback(IAsyncResult asyncResult) { HttpWebRequest objHttpWebRequest = (HttpWebRequest)asyncResult.AsyncState; // End the operation Stream postStream = objHttpWebRequest.EndGetRequestStream(asyncResult); Debug.WriteLine("streeaam: " + postStream.ToString()); // Convert the string into a byte array. Debug.WriteLine("RequestData: " + myRequestData); byte[] byteArray = Encoding.UTF8.GetBytes(myRequestData); // Write to the request stream. postStream.Write(byteArray, 0, myRequestData.Length); postStream.Close(); // Start the asynchronous operation to get the response objHttpWebRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), objHttpWebRequest); } private static void GetResponseCallback(IAsyncResult asyncResult) { try { HttpWebRequest objHttpWebRequest = (HttpWebRequest)asyncResult.AsyncState; HttpWebResponse objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.EndGetResponse(asyncResult); Stream objStreamResponse = objHttpWebResponse.GetResponseStream(); StreamReader objStreamReader = new StreamReader(objStreamResponse); string responseString = objStreamReader.ReadToEnd(); // Got response here Debug.WriteLine("Response: " + responseString); MessageBox.Show("RESPONSE :" + responseString); // Close the stream object objStreamResponse.Close(); objStreamReader.Close(); objHttpWebResponse.Close(); } catch (WebException e) { HttpStatusCode code = ((HttpWebResponse)(e).Response).StatusCode; Debug.WriteLine("Errorr: " + code.ToString()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)