0

私の大学の成績表 (結果) は非常に複雑で、実際の学生の割合を計算するのは非常に困難です。そこで、学生が登録番号を入力するだけでよいサービスを学生に提供したいと考えています。そして結果は自分で計算します。

最初に、 http://hurl.itの成績表ページにポスト リクエストを送信しようとしまし た。パーマ リンクは次のとおりです

しかし、私のウェブサイトから jquery を使用して同じリクエストを送信すると、エラーが発生します。次のコードを使用してリクエストを送信しています。

            $.ajax({
                type: "POST",
                url: "http://stusupport12.ignou.ac.in/Result.asp",
                data: "submit=Submit&eno=092853268&hidden%5Fsubmit=OK&Program=BCA",
                success: function (d) {
                    $("#resultDiv").html(d);
                },
                error: function (a, b, c) { alert(a + b + c); }
            });

友達を助けてください。

更新 2 - サーバーでリクエストを処理してソリューションを見つけました。サーバーで要求を処理し、処理された要求をクライアントに送り返す汎用ハンドラー (.ashx) を作成しました。Jqueryで呼び出すことができます。

ここにコードがあります

<%@ WebHandler Language="C#" Class="IGNOU" %>

using System;
using System.Web;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net;
using System.IO;

public class IGNOU : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        context.Response.Write(Func(context.Request.QueryString["eno"]));
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
    public string Func(string eno)
    {
        string str = string.Empty;
        WebRequest request = WebRequest.Create("http://stusupport12.ignou.ac.in/Result.asp");
        // Set the Method property of the request to POST.
        request.Method = "POST";
        // Create POST data and convert it to a byte array.
        string postData = "submit=Submit&Program=BCA&hidden_submit=OK&eno=" + eno;
        byte[] byteArray = System.Text.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();

        return responseFromServer;
    }
}

更新 1 Web ページへのリンクを追加 https://www.bobdn.com/IGNOU_BCA_Result.aspx

4

3 に答える 3

1

このエラーはクロスドメイン ポリシーによるものです。応答は正しいデータで返されますが、送信元が同じではないため、ブラウザ自体が応答をブロックしています。

Twitter でわかるように、これはクロス ドメイン ポリシーです。次のような内容のファイルを のルートにhttps://twitter.com/crossdomain.xml配置する必要があります。crossdomain.xmlstusupport12.ignou.ac.in

<?xml version="1.0" encoding="UTF-8"?>
<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFile.xsd">
  <allow-access-from domain="www.bobdn.com" />
</cross-domain-policy>

私のasp.netモックアップ:

byte[] buffer = Encoding.UTF8.GetBytes("submit=Submit&eno=092853268&hidden%5Fsubmit=OK&Program=BCA");

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://stusupport12.ignou.ac.in/Result.asp");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.CookieContainer = new CookieContainer(); // enable cookies 

Stream reqst = req.GetRequestStream(); // add form data to request stream
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close(); 
于 2012-05-10T16:22:18.277 に答える
0

ポイントは次のとおりです。

あなたが参照しているサイト (hurl.it) は、実際にはサーバー サイド スクリプトを使用して、そのサーバーをプロキシとして機能させ、結果を取得します。Same Origin Policy のため、クライアント側でこのようなリクエストを実行できないことは間違いありません。

このようなリクエストを自由に行うことができると想像してください。他の誰かのサーバーに、フィルタリングされていない多数の呼び出しをロードできるため、何千もの異なる IP からの呼び出しが割り当てられ、サービスに参照できなくなります。これが、SOP が、これらの要求を監視して指示するために、間に独自のサーバーを配置するように求める理由です。

もう 1 つの解決策は、クライアント側の呼び出しを受信するように API サービスをセットアップするリモート サーバーであり、正常に動作する JSON 応答を返します。ほとんどすべての API サービスは、追加のパラメーターを必要としますが、これはドメインに関連付けられた個人の開発者キーであり、いずれにせよそれらのリクエストがどこから来たのかを知ることができます。

于 2012-05-10T17:00:54.500 に答える
0

私の推測では、エラーは関数宣言function (a, b, c)ではなく、アラートにあると思います。は恐ろしい変数名であることに同意します。特に b/cが XMLHttpRequest オブジェクトであり、が文字列a, b, cであることは明らかではありません。 これに気づけば、簡単にエラーが表示されます - XMLHttpRequest オブジェクトを文字列と連結できません。abc

ここでエラー関数に関するドキュメントを参照してください: http://api.jquery.com/jQuery.ajax/

于 2012-05-10T15:48:40.150 に答える