我正在寻找从HTTPWebRequest
删除某些元素我附加了我需要在图像中删除的元素(元素显示为红色):
我试过了:
System.Net.ServicePointManager.Expect100Continue = False
其中一个元素但无济于事 我也试过了:
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)
然后在我的webservice的reference.vb中:
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
答案 0 :(得分:1)
您想要从HTTP消息中删除一些更详细的标题?
你能做的一件容易的事就是:
webRequest.ProtocolVersion = HttpVersion.Version10
其中一些标题不在HTTP的1.0版本中,只存在于1.1版本(Key Differences)中,因此降级到1.0版本应该处理很多“额外标题”你。
如果你想摆脱Content-Length标题,那么我很确定你必须从POST切换到GET。如果你正在进行POST,那么通常需要Content-Length!
如果那样做不适合你那么你将不得不走最后一步并停止使用HttpWebRequest(它正在为你做很多HTTP工作)并且只做一个普通的TCP连接(也许是TcpClient类?)并指定要发送的确切HTTP消息。这是一项更多的工作,但这可能是发送一个非常具体的消息的唯一方法,您可以控制所有正在使用的HTTP标头。
希望有所帮助!