0

我正在寻找从图像中删除某些元素,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)

然后在我的网络服务的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
4

1 回答 1

1

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

webRequest.ProtocolVersion = HttpVersion.Version10

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

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

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

希望有帮助!

于 2011-12-12T16:59:58.297 回答