【问题标题】:Removal of HTTP webrequest elements删除 HTTP webrequest 元素
【发布时间】:2011-12-12 15:01:44
【问题描述】:

我希望从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)

然后在我的 web 服务的 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

【问题讨论】:

  • 你能发布你想要实现的全部代码吗?
  • 提示#1:停止使用 WSE。它已经过时了。
  • 为什么您认为您需要更改这些标题?虽然看起来在 SOAPAction 标头值之一周围使用了错误的引号。
  • 我已经对此进行了排序.. 不需要更改肥皂动作标题值

标签: .net vb.net soap webrequest wse3.0


【解决方案1】:

您想从 HTTP 消息中删除一些更详细的标头吗?
您可以做的一件简单的事情是:

webRequest.ProtocolVersion = HttpVersion.Version10

其中一些标头不在 1.0 版本的 HTTP 中,仅存在于 1.1 版本 (Key Differences),因此降级到 1.0 版本应该会为您处理很多这些“额外的标头”。

如果您想摆脱 Content-Length 标头,那么我很确定您必须从 POST 切换到 GET。如果您正在执行 POST,则通常需要 Content-Length!

如果这对您不起作用,那么您将不得不进行最后一步并停止使用 HttpWebRequest(它正在为您完成大量 HTTP 工作),而只需进行普通 TCP 连接(可能使用TcpClient 类?)并指定要发送的确切 HTTP 消息。这需要更多的工作,但这可能是发送非常具体的消息的唯一方法,您可以控制所有正在使用的 HTTP 标头。

希望有帮助!

【讨论】:

    猜你喜欢
    • 2013-07-18
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多