删除HTTP webrequest元素 [英] Removal of HTTP webrequest elements
问题描述
我正在寻找从 HTTPWebRequest
中删除某些元素的方法,我已经在图像中附加了需要删除的元素(元素以红色显示):
I'm looking to remove certain elements from a HTTPWebRequest
I have attached the elements I need to remove in an image (elements are coloured red):
我尝试过:
System.Net.ServicePointManager.Expect100Continue = False
表示要素之一,但无济于事我也尝试过:
for one of the elements but to no avail I've also tried:
webRequest.Headers.Remove(HttpRequestHeader.Connection)
任何帮助将不胜感激.
这是我的代码:
Dim content As blah.Content = New blah.Content
Dim inputguid As String = Guid.NewGuid.ToString
Dim service As blah.WebService = New blah.WebService
Dim str As New System.Xml.XmlDocument
Dim payload As blah.Payload = New blah.Payload
System.Net.ServicePointManager.Expect100Continue = False
'payload
str.LoadXml(xmlstr)
'manifest
service.payloadManifest = New blah.PayloadManifest
service.payloadManifest.manifest = New blah.Manifest() {New blah.Manifest}
service.payloadManifest.manifest(0).element = "GetVehicleServiceHistory"
service.payloadManifest.manifest(0).namespaceURI = "http://www.starstandards.org/STAR"
service.payloadManifest.manifest(0).contentID = "Content0"
service.payloadManifest.manifest(0).version = "2.01"
service.SoapVersion = SoapProtocolVersion.Soap11
service.UserAgent = "VendorName"
payload.content = New blah.Content() {content}
ReDim Preserve payload.content(0)
payload.content(0).Any = str.DocumentElement
payload.content(0).id = "Content0"
service.Timeout = -1
service.Url = "http://localhost:8080"
service.ProcessMessage(payload)
,然后在我的网络服务的reference.vb中:
and then within the reference.vb of my webservice:
Protected Overrides Function GetWebRequest(ByVal uri As Uri) As WebRequest
Dim webRequest As HttpWebRequest = DirectCast(MyBase.GetWebRequest(uri), HttpWebRequest)
Dim sp As ServicePoint
sp = ServicePointManager.FindServicePoint(New Uri(Me.Url))
sp.ConnectionLeaseTimeout = 0
webRequest.Headers.Remove(HttpRequestHeader.Connection)
webRequest.KeepAlive = False
webRequest.Timeout = 100000
webRequest.ReadWriteTimeout = 100000
Return webRequest
End Function
推荐答案
您想摆脱HTTP消息中一些更详细的标头吗?
您可以做的一件简单的事情就是:
You would like to get rid of some of the more detailed headers from your HTTP message?
One easy thing you can do would be this:
webRequest.ProtocolVersion = HttpVersion.Version10
其中一些标头不在HTTP的1.0版本中,而仅存在于1.1版本中(
Several of those headers aren't in the 1.0 version of HTTP and only exist in the 1.1 version (Key Differences), so downgrading to the 1.0 version should take care of a lot of those 'extra headers' for you.
如果您想摆脱Content-Length标头,那么我很确定您必须从POST切换到GET.如果您要进行POST,则通常需要Content-Length!
If you want to get rid of the Content-Length header, then I'm pretty sure you'll have to switch from POST to GET. If you're doing a POST, then Content-Length is typically required!
如果那对您不起作用,那么您将必须走最后一步并停止使用HttpWebRequest(这为您完成了许多HTTP工作),而只是进行了简单的TCP连接(也许 TcpClient 类?)并指定确切的您要发送的HTTP消息.还有很多工作要做,但这可能是发送非常具体的消息的唯一方法,您可以在其中控制所有正在使用的HTTP标头.
If that just doesn't do it for you then you'll have to go the final step and stop using HttpWebRequest (which is doing a lot of the HTTP work for you) and just do a plain TCP connection (perhaps with the TcpClient class?) and specify the exact HTTP message you want to send. It's a lot more work, but that's likely to be the only way to send a very specific message where you control all the HTTP headers being used.
希望有帮助!
这篇关于删除HTTP webrequest元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!