4

XMLを支払いエンジンに送信する必要がある従来のaspアプリがあり、参照コードはSystem.Net.HttpWebRequestオブジェクト(asp.net)を使用しています。XMLを投稿するために使用できるClassicASPに相当するものはありますか?

4

4 に答える 4

6

ASP で HTTP 要求を作成するために使用する小さなヘルパー関数を次に示します。これは JScript にありますが、少なくともアイデアと、何年にもわたって解決しなければならなかったいくつかの厄介な落とし穴のいくつかの指針を得る必要があります。

<%

/*
   Class: HttpRequest
       Object encapsulates the process of making an HTTP Request.

   Parameters:
      url - The gtarget url
      data - Any paramaters which are required by the request.
      method - Whether to send the request as POST or GET
      options - async (true|false): should we send this asyncronously (fire and forget) or should we wait and return the data we get back? Default is false

   Returns:
      Returns the result of the request in text format.

*/

var HttpRequest = function( url, data, method, options  )
{
    options = options ? options : { "async" : false };
    options[ "async" ] = options["async"] ? true : false;

    var text = "";
    data = data ? data : "";
    method = method ? String( method ).toUpperCase() : "POST";

    // Make the request
    var objXmlHttp = new ActiveXObject( "MSXML2.ServerXMLHTTP" );
    objXmlHttp.setOption( 2, 13056 ); // Ignore all SSL errors

    try {
        objXmlHttp.open( method, url, options[ "async" ] ); // Method, URL, Async?
    }
    catch (e)
    {
        text = "Open operation failed: " + e.description;
    }

    objXmlHttp.setTimeouts( 30000, 30000, 30000, 30000 );   // Timeouts in ms for parts of communication: resolve, connect, send (per packet), receive (per packet)
    try {
        if ( method == "POST" ) {
            objXmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
        }

        objXmlHttp.send( data );

        if ( options[ "async" ] ) {
            return "";
        }

        text = objXmlHttp.responseText;

    } catch(e) {
        text = "Send data failed: " + e.description;
    }

    // Did we get a "200 OK" status?
    if ( objXmlHttp.status != 200 )
    {
        // Non-OK HTTP response
        text = "Http Error: " + objXmlHttp.Status + " " + Server.HtmlEncode(objXmlHttp.StatusText) + "\nFailed to grab page data from: " + url;
    }

    objXmlHttp = null; // Be nice to the server

    return  text ;
}

%>

これをファイル (httprequest.asp という名前) に保存すると、次のコードを使用して使用できます。

<%@ Language="JScript" %>
<!--#include file="httprequest.asp"-->
<%

var url = "http://www.google.co.uk/search";
var data = "q=the+stone+roses"; // Notice you will need to url encode your values, simply pass them in as a name/value string

Response.Write( HttpRequest( url, data, "GET" ) );

%>

エラーがある場合、エラーメッセージが返されますが、それをキャッチする方法はありません。もう少し保護が必要な場合は、エラーをより適切に処理できるカスタム関数を作成できます。

それが役立つことを願っています。

于 2009-06-01T13:23:34.863 に答える
4

従来の ASP は、XMLHTTPActiveX オブジェクトまたはServerXMLHTTPMSXML ライブラリ経由で利用可能なオブジェクトを使用して、要求を開始できます。( MSDN リファレンス)。

この KB 記事は、オブジェクトの適切な参照とサンプル コードを提供しServerXMLHTTPます。

于 2009-06-01T06:03:42.337 に答える
2

この関数の非同期バージョンが機能し、ここで説明されている「送信なし」エラーを回避する理由は次のとおりだと思います。

asp classic で非同期呼び出しを起動し、応答を無視するにはどうすればよいですか?

Async バージョンで COM オブジェクトを決して解放していないということですか。問題が修正されるのは良いことですが、リソースが大量にリークするのは悪いことです。

于 2011-02-22T23:06:08.587 に答える
1

AJAXyはすべてXMLHttpを使用します。
このリンクが役立つかどうかを確認してください-http ://www.mikesdotnetting.com/Article.aspx? ArticleID=39

編集:この答えを受け入れないでください。
私がしたのは、グーグルを使ってそれを検索することです。最初に試しましたか?

いくつかの質問は検索で答えられると思います。
他のすべてのために、StackOverflowがあります。

于 2009-06-01T04:25:21.367 に答える