我想知道這個「POST」請求是幹什麼的,並且將代碼翻譯成vb.net,以用於webrequest。會評論我所知道的已經Javascript to VB.Net [FEW LINES]
var xmlhttp; //Defining the "xmlhttp" variable
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest()
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
}
xmlhttp.onreadystatechange = function() { //If the xmlhttp is created then do this:
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { //Don't know
fired = true; //The function gathered the conditions to start
var title = '<div id="message_box_title_unavailable">woops!</div>'; //Doesn't matter
var result; //Variable "result"
if (xmlhttp.responseText == 'available') { //If the xml file contains "available" on it then do this, else return an error...
result = 'The name you selected <strong>' + user + 'is available!'
} else {
result = 'There was an error processing your request. Please try again.'
}
}
};
xmlhttp.open("POST", "Checkusername.php", true); //Didn't I translate this correctly?
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //What am I missing from this line in my vb code?
xmlhttp.send("name=" + name + "&n=" + Math.random()) //The same...
}
好了 - 我Vb的翻譯
Dim req As HttpWebRequest
Dim res As HttpWebResponse
Dim cookies As New CookieContainer()
req = WebRequest.Create("http://blablabla.net/Checkusername.php?name=" & name "&n=" R.Next(0, 20000))
req.Method = "POST"
req.ContentType = "application/xml"
req.Headers.Add("Content-type", "application/x-www-form-urlencoded")
req.CookieContainer = cookies
res = req.GetResponse
Dim webStream As Stream
webStream = res.GetResponseStream
Dim reader As New StreamReader(webStream)
checksource.text = reader.readtoend
這總是返回我的「錯誤」,而不是期望的結果,這是在HTML總是正確
基本上,我不能翻譯3/5行和最後3行。
感謝您的幫助!
請分享整個錯誤消息 – OneFineDay 2014-12-07 00:23:43