Question

I need to call .php page from my aspx.cs page.but I don't want to load the page.I just want to call the page and the page will give me XLM response that I need to store in DB.I am trying this with the Ajax,but according to this link.We are not be able to call cross domain page from ajax.

In short I want to read the data from php page using asp.net code.

can anybody please help me out.

Update :: Is the P3P policy will usefull in case of cross domain page calling.

Was it helpful?

Solution

I got the solutions,thanks for your help.

create a new WebClient object

WebClient client = new WebClient();

string url = "http://testurl.com/test.php";

create a byte array for holding the returned data

byte[] html = client.DownloadData(url);

use the UTF8Encoding object to convert the byte array into a string

UTF8Encoding utf = new UTF8Encoding();

get the converted string

string mystring = utf.GetString(html);

OTHER TIPS

If I understand you correctly, your problem is that you want to do a cross-domain ajax call - which is not possible. The way to go around this is to make a call to your own backend which then fetches the data from the other site and sensd it back to the browser. Remember to do any needed safety check in the back end - depending on how much you trust the other domain of cource... (but even if you trust it 100%, it may be hacked or have some other problems that makes it return something else than what you tink it returns)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top