我想使用 vb.net 创建 get and forget Url。基本上我会推送一个 url(只是从 url 获得响应,而不是在浏览器中显示/在后台运行)然后忘记。我想在单击按钮时同时推送 10 个 url。这是我的代码,但它仍然一一处理网址。
Private Sub BtnHit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHit.Click
Dim startp As DateTime = New DateTime(CDate(BtnStartDate.Text.ToString).Year, CDate(BtnStartDate.Text.ToString).Month, CDate(BtnStartDate.Text.ToString).Day)
Dim endp As DateTime = New DateTime(CDate(BtnEndDate.Text.ToString).Year, CDate(BtnEndDate.Text.ToString).Month, CDate(BtnEndDate.Text.ToString).Day)
Dim CurrD As DateTime = startp
'Call PostTo("http://localhost:8089/Process/GetDataRencanaLembur.aspx?sid=88665765746873243", "POST", "&NIP=000323971&START_DATE=18 Aug 2015&END_DATE=19 Aug 2015")
While (CurrD <= endp)
Call PostTo("http://" & My.Settings.UrlServer & "/Process/SubmitRencanaLembur.aspx?sid=" & ((DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString.Trim, "POST", "&NOREG=" & Noreg.Trim & "&Nama=" & LblNama.Text.Trim & "&DirectReport=" & LblDirectReport.Text.Trim & "&Tanggal=" & Format(CurrD, "dd MMM yyyy") & "&OTPlan=03%3A00&Reason=Robot Testing")
CurrD = CurrD.AddDays(1)
End While
end sub
Protected Sub PostTo(ByVal url As String, ByVal method As String, ByVal postData As String)
CreateLog("Start Time : " & Now.ToString("HH:mm:ss.fff"))
Dim stopwatch As Stopwatch = stopwatch.StartNew()
Dim myWebRequest As HttpWebRequest = TryCast(WebRequest.Create(url), HttpWebRequest)
myWebRequest.Method = method
Dim byteArray As Byte() = System.Text.Encoding.[Default].GetBytes(postData)
myWebRequest.ContentType = "application/x-www-form-urlencoded"
myWebRequest.ContentLength = byteArray.Length
Dim dataStream As System.IO.Stream = myWebRequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
LblStatus.Text = (DirectCast(myWebResponse, HttpWebResponse)).StatusCode & " " & (DirectCast(myWebResponse, HttpWebResponse)).StatusDescription
dataStream = myWebResponse.GetResponseStream()
Dim reader As New System.IO.StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
RichTextBox1.Text = RichTextBox1.Text & vbNewLine & responseFromServer + ":"
reader.Close()
dataStream.Close()
myWebResponse.Close()
CreateLog("End Time : " & Now.ToString("HH:mm:ss.fff"))
CreateLog("Parameter : " & postData & vbNewLine & "Status Code : " & LblStatus.Text & " " & stopwatch.ElapsedMilliseconds & "ms" & vbNewLine & "URL : " & url & postData & vbNewLine & "Response From Server : " & responseFromServer & vbNewLine)
End Sub