1

Silverlight WP7でGETおよびPOSTメソッドを使用するにはどうすればよいですか?

通常のasp.netアプリケーションでgetおよびpostメソッドを完了しましたが、WindowsPhoneテクノロジーを使用してSilverlightで実行する方法がわかりません。

通常のasp.netのHTTPPostメソッド

<form method="post" name="ePayment" action="https://www.mobile88.com/ePayment/entry.asp">

HTTPGetメソッド

<input type="submit" value="Proceed with Payment" name="Submit">
<input type="hidden" name="ResponseURL" value="http://localhost:2017/iPay88/response.aspx">

解決策が必要です

private void ReadCallback(IAsyncResult asynchronousResult)
        {


            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
            {
                string resultString = streamReader1.ReadToEnd();
                MessageBox.Show("Using HttpWebRequest: " + resultString, "Found", MessageBoxButton.OK);
            }

        }

        void SendPost()
        {
            var url = "https://www.mobile88.com/ePayment/entry.asp";

            // Create the web request object
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";

            // Start the request
            webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);




        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            SendPost();
        }
        void GetRequestStreamCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
            // End the stream request operation
            Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);

            // Create the post data
            // Demo POST data 
            string postData = "data=iVBORw0KGgoAAAANSUhEUgAAAFoAAAASCAYAAADbo8kDAAAKyElEQVR4nG2YB3TNVxzHm5eEDHuF2GJUjVRqb2okiMRWqtG0KKI4aq8mUQQ5FRWrhNi1Z6lWazSrRm1iVBDESiIxEkH6Pu/069zzTt857/zv//5/e9/73tu3bx3s/2/evLHk5eU5vX792pG19vT91atXzlo/f/7cTWtweL58+dLFpGW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tSJdc0kE8Vf8tutDRxYpqsXnjBhNdIomobtNYUxI0gZAdarD2+GIuZ4mXaQw5lie8ZGAMY8pnTjpyCkpJF53I9E3NXFe9GMN+bJPh1dhN+uDrgkvy6Bt2YU83hnKAHGijJ4/ooKDDhBTWAcGcYcUETymNEVqe5LsMDp4Gdwll3sDpEGJeVbJnRrkizbxatTeGIg85dKGliNI1KU/JaO8gXcVqXyVEcsiYkkcThmZ98DViSm+VJt7/BbjvID507t6TAAAAAElFTkSuQmCCTHEEND";

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Add the post data to the web request
            postStream.Write(byteArray, 0, byteArray.Length);
            postStream.Close();

            // Start the web request
            webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
        }

        void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response;

                // End the get response operation
                response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
                Stream streamResponse = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(streamResponse);
                var Response = streamReader.ReadToEnd();
                streamResponse.Close();
                streamReader.Close();
                response.Close();

            }
            catch (WebException e)
            {
                // Error treatment
                // ...
            }
        }

これは私が試したコードブロックですが、これが正しいかどうかわかりませんでした。正しい方法を教えてください。

4

0 に答える 0