PDA

View Full Version : دریافت جواب یک Redirect



OlympicTelecom
پنج شنبه 08 آذر 1386, 17:36 عصر
سلام دوستان:
من می خواهم اطلاعاتی را با queyString به یک صفحه ارسال کنم مثلا


Default.aspx?User=ali

حالا اون صفحه فرضا یک OK را چاپ می کنه یعنی UserName رو دریافت می کنه و بعد با Response.Write یک OK چاپ می کنه!

حالا من چطور به اون OK دسترسی داشته باشم توی صفحه مبدا!!
با آژاکس تونستم بوسیله جاوا اسکریپت OK رو بگیرم ولی چند تا مشکل دارم اول اینکه صفحه مقصد مال یک سایت دیگه است و IE یک اخطار میده که حتما باید OK کنی اش و الا عملیات انجام نمیشه که من نمی خوام اینجوری باشه ، دوم هم وقتی OK را با جاوا اسکریپت می گیرم نمی دونم چطور توی برنامه ازش استفاده کنم !!؟؟ من با اینا رو نوشتم با آژاکس :



<script language="javascript">
var xmlhttp=null;

function Create(){
if (window.ActiveXObject){
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}else{
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function GetStr(){
Create();
xmlhttp.open('GET','default.aspx?username=ali',tru e);
xmlhttp.onreadystatechange = update;
xmlhttp.send(null);
}

function update(){
if (xmlhttp.readyState == 4){
if (xmlhttp.status == 200){
var message = xmlhttp.responseText;
document.getElementById("mdiv").innerHTML = message;
}else{
alert("Error");
}
}
}

</script>

اگر دقت کنید من با متغیر message چیزی رو که صفحه مقصد بر میگردونه گرفتم فقط موندم چطور ازش توی مثلا Page_Load برنامم استفاده کنم !!

خواهشا کمک کنید که موضوع ناموسی ! (سر کل کل)

OlympicTelecom
پنج شنبه 08 آذر 1386, 22:29 عصر
کسی راه حلی نداشت !؟

OlympicTelecom
جمعه 09 آذر 1386, 20:31 عصر
همچنان در انتظار !!

OlympicTelecom
جمعه 09 آذر 1386, 22:29 عصر
جواب رو پیدا کردم ، می نویسم باشد برای آیندگان !

با استفاده از متد Get :

Imports System.IO
Imports System.Net
Partial Class Default1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strURL As String
Dim strResult As String
Dim wbrq As HttpWebRequest
Dim wbrs As HttpWebResponse
Dim sr As StreamReader

' Set the URL (and add any querystring values)
strURL = "http://aspnetlibrary.com/articles.aspx?Page=1"

' Create the web request
wbrq = WebRequest.Create(strURL)
wbrq.Method = "GET"

' Read the returned data
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetResponseStream)
strResult = sr.ReadToEnd.Trim
sr.Close()

' Write the returned data out to the page
TextBox1.Text = strResult
End Sub
End Class


با استفاده از متد POST :

Imports System.IO
Imports System.Net
Partial Class Default1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strURL As String = ""
Dim strPostData As String = ""
Dim strResult As String = ""
Dim wbrq As HttpWebRequest
Dim wbrs As HttpWebResponse
Dim sw As StreamWriter
Dim sr As StreamReader

' Set the URL to post to
strURL = "http://www.webcom.com/cgi-bin/form"
' Post some values to the page
strPostData = String.Format("your_name={0}&userid={1}&form_name={2}", "Mark Smith", "webcom", "tutortest")

' Create the web request
wbrq = WebRequest.Create(strURL)
wbrq.Method = "POST"
' We don't always need to set the Referer but in this case
' the page we are posting to will only issue a response if we do
wbrq.Referer = "http://www.webcom.com/cgi-bin/form"
wbrq.ContentLength = strPostData.Length
wbrq.ContentType = "application/x-www-form-urlencoded"

' Post the data
sw = New StreamWriter(wbrq.GetRequestStream)
sw.Write(strPostData)
sw.Close()

' Read the returned data
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetResponseStream)
strResult = sr.ReadToEnd.Trim
sr.Close()

' Write the returned data out to the page
TextBox1.Text = strResult
End Sub
End Class