|
当连续请求同一网址时会出现请求头里没有Connection=Keep-Alive这个。可以通过以下反射调用内部函数进行解决
Private Sub SetHeaderValue(ByVal header As WebHeaderCollection, ByVal name As String, ByVal value As String)
Dim [property] = GetType(WebHeaderCollection).GetProperty("InnerCollection", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
If [property] IsNot Nothing Then
Dim collection As NameValueCollection = [property].GetValue(header, Nothing)
collection(name) = value
End If
End Sub
If item.KeepAlive Then
SetHeaderValue(request.Headers, "Connection", "Keep-Alive")
Else
request.KeepAlive = item.KeepAlive
End If
vb.net代码,要c#的可以自行转换后添加上去。不知道有没有人有其他方式可以解决这个问题。
|
|