1

一部のデータを PHP ページに POST し、ユーザーをそのページにリダイレクトしてデータを表示する必要がある C# カート アプリケーションがあります。すべてがうまくいっています!それで、問題は何ですか??

Javascript 関数を使用してアクションを PHP URL に設定し、フォームを PHP ページに POST しているため、カートの内容でセッション変数をクリアできません。

ユーザーがチェックアウトをクリックしてサードパーティのサイトに送信されたら、カートの内容を保存するセッション変数を削除します。私の知る限り、Javascript を介してこれをクリアすることはできないため、C# コードを介して POST データとユーザーを PHP ページに送信することを考えました。

ユーザーがチェックアウトをクリックすると、Javascript がページをリロードし、カート データを文字列変数に設定し、セッションをクリアしてから、データを POST し、ユーザーを PHP ページに送信します。

データの POST とユーザーのリダイレクトを除いて、これはすべて機能しています。残念ながら、サードパーティのページはセキュリティ上の理由から URL.PHP?=var タイプのパラメーターを受け入れることができないため、POST する必要があります。

WebRequest を使用すると、投稿されたデータを取得できると思いますが、ユーザーをそのページにリダイレクトして注文を完了することはできません。何か案は?

4

3 に答える 3

2

データを準備し、セッションをクリーンアップするための中間ページを実装することをお勧めします。「チェックアウト」リンクは、ユーザーをこの中間ページに移動するだけで、次のようになります。

  1. セッションからユーザーのカートデータを収集する
  2. セッションをクリアする
  3. WebRequestを使用してPHPページにPOSTする

WebRequestのMSDNから:

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
    public class WebRequestPostExample
    {
        public static void Main ()
        {
            // Create a request using a URL that can receive a post. 
            WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = "This is a test that posts this string to a Web server.";
            byte[] byteArray = Encoding.UTF8.GetBytes (postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream ();
            // Write the data to the request stream.
            dataStream.Write (byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close ();
            // Get the response.
            WebResponse response = request.GetResponse ();
            // Display the status.
            Console.WriteLine (((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader (dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd ();
            // Display the content.
            Console.WriteLine (responseFromServer);
            // Clean up the streams.
            reader.Close ();
            dataStream.Close ();
            response.Close ();
        }
    }
}
于 2009-07-22T19:19:55.983 に答える
0

Javascriptソリューションを使い続けて、セッションを放棄するAjax呼び出しを追加するだけです。

于 2009-07-22T18:08:48.060 に答える
0

ここでは推測しているだけですが、WebBrowser コントロール項目でデータを送信できるはずです。そのようにして、投稿データを送信してリダイレクトします。

于 2010-04-22T10:32:24.730 に答える