0

My University grade card (result) is very complex to understand and It is very hard to calculate actual percentage of a student. So, I want to provide students a service where student will just need to enter there enrollment number. And I will calculate result my self.

Very firstly, I tried to send a post request to grade card page in http://hurl.it Here is the perm link http://hurl.it/hurls/c61f1d38b6543965151a1c8a8d6f641b8921da49/986ecba51b61022fa9fa162be612d7c928051989

But I am getting error when sending same request using jquery from my website: I am using following code to send request.

            $.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); }
            });

Please help me friends.

Update 2 - I find my Solution by processing the request on my server. I'd created a Generic Handler (.ashx) that handles the request on server and send the processed request back to client. I can call it by Jquery.

Here is the code

<%@ 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;
    }
}

Update 1 Added link to web page https://www.bobdn.com/IGNOU_BCA_Result.aspx

7
  • 3
    you cannot perform cross domain ajax unless you get a JSON/JSONP object as response Commented May 10, 2012 at 15:38
  • @ocanal in error: function (a, b, c). It is just an error. No detail provided. Commented May 10, 2012 at 15:40
  • 1
    Why would you use a, b, c as variable names. That sucks. Commented May 10, 2012 at 15:41
  • @Onheiron hurl.it can do it. Why I can't. check this link hurl.it/hurls/c61f1d38b6543965151a1c8a8d6f641b8921da49/… Commented May 10, 2012 at 15:42
  • I also tried using error: function OnError(request, status, error). I am getting same error with this too @RepWhoringPeeHaa Commented May 10, 2012 at 15:46

3 Answers 3

1

This error is due to crossdomain policy, the response is coming back with the correct data however the browser itself is blocking the response because it is not same origin.

As you can see on twitter https://twitter.com/crossdomain.xml this is the cross domain policy, you will need to place a crossdomain.xml file in the root of stusupport12.ignou.ac.in with the contents like:

<?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>

My asp.net mockup:

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(); 
Sign up to request clarification or add additional context in comments.

4 Comments

I do not have access to the server of University. How can I do this..?? Is there any alternate..?? can I process this request on server side using asp.net with C#..???? please help
The way to bypass crossdomain policy in PHP is to use a cURL wrapper. By making a post call server side you will bypass the restrictions.
can't I make post call from asp.net in server side..??
I am not an ASP.net developer, but from what I hove found it would be something like the amended code to send the request.
0

my guess is that the error is not in the function declaration function (a, b, c), but in the alert. I agree that a, b, c are horrible variable names - in particular b/c it is not obvious that a is an XMLHttpRequest object, while b and c are strings.
If you realize that, you will easily see the error - cant concat the XMLHttpRequest object with a string.

See the docs about the error function here: http://api.jquery.com/jQuery.ajax/

6 Comments

dear while analyzing request using HttpFox (add on in firefox). I found that the error is Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED). I double checked the url. There is no error in url. You can also see that. Same url in hurl.it working
I think this question has your answer there: stackoverflow.com/questions/4038299/… as Onheiron said - cannot cross domain post ajax without JSONP
may be the error is text/html (NS_ERROR_DOM_BAD_URI) I see this in httpfox somewhere
different error msg for the same basic problem. see: stackoverflow.com/questions/1105055/…
see here for an example using <code>jsonp</code> request: stackoverflow.com/questions/1002367/…
|
0

Here is the point:

The site you refer to (hurl.it) actually uses server side scripta making its server act as a proxy and retriving the results for you. I am absolutely positive you cannot perform such request client side because of the Same Origin Policy.

Imagine you can do such a request freely, you would be able to load someone else's server with thons of unfiltered calls, thus allot of calls coming from thousands of different IPs and not referable to your service. This is why SOP asks you to put your own server in between in order to monitor and direct those requests.

Another solution would be the remote server to setup an API service to receive client side calls, thus returning JSON responses which will work fine. Preatty much all API services althought require an extra parameter which would be your personal developer key associated with your domain so they can in any case know where those requests come from

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.