HTTP post cannot reach host in very specific situations

52 Views Asked by At

My company posts invoices to both Ariba and Oracle Supplier Networks via HTTP POST. We've had an issue where we haven't been able to determine whether it comes from its settings or code.

Below is the code:

Public Function SendMime(pFiles As List(Of String)) As String
    'just use the text send option in HTTP connection
    If pFiles.Count = 1 And pFiles.Item(0).EndsWith(".xml") Then
        Return Send(My.Computer.FileSystem.ReadAllText(pFiles(0)))
    End If

    Dim Request As Net.HttpWebRequest

    Request = DirectCast(Net.WebRequest.Create(GetFirstURL()), Net.HttpWebRequest)
    Request.ContentType = "multipart/related;boundary=" & OuterBoundary & ";type=""text/xml"";start=""<" & _CID & ".1>"""
    Request.Method = "Post"
    Request.KeepAlive = True

    WriteRequest(Request, pFiles)

    Dim Response As Net.WebResponse
    Try
        Response = Request.GetResponse()
        Dim ResponseStream As Stream = Response.GetResponseStream()
        Dim ResponseReader As New StreamReader(ResponseStream)
        Return ResponseReader.ReadToEnd()
    Catch ex As System.Exception
        Return "error: " & ex.Message
    End Try
End Function

Private Sub WriteRequest(pRequest As Net.WebRequest, pFiles As List(Of String))
    Dim PartCount As Integer = 1

    _RequestStream = pRequest.GetRequestStream()
    _tempStream = New FileStream("C:\lastMIMEsent.txt", FileMode.Create)

    For Each File As String In pFiles
        WriteBoundary(OuterBoundary)
        If File.ToLower.EndsWith(".xml") Then
            GetXMLPart(File, PartCount)
        ElseIf File.ToLower.EndsWith(".pdf") Then
            GetPDFPart(File, PartCount)
        End If
        PartCount += 1
    Next

    WriteTrailer(OuterBoundary)

    _RequestStream.Close()
    _tempStream.Flush()
    _tempStream.Close()

End Sub

The send function is similar to the SendMime function, but with no attachments (cXML only). This code is shared between a Windows Service and a basic GUI test program.

edit: The error I get is:

Unable to connect to host

Where things get weird:

  • On the server running the service: Oracle works, Ariba does not, when the service calls the SendMime function.
  • On the server running the service: Both work, when the GUI utility calls the SendMime function.
  • On my work station: both work, regardless of whether it is the service or GUI calling the SendMime function
  • My first thought was Proxy, but both machines are behind the same proxy.
  • My second thought was Firewall issues, but we disabled the firewall with no success.
  • We can connect to the address via web browser as well.
  • We tried with different Active Directory accounts, with no change as well.
  • Both the service and the GUI utility are running .Net 4.5 (needed for some asynchronous parts of the service). They were not at one point, but upgrading the Utility made no difference.
  • The only difference I can find, is that my machine runs Windows 7 and the server runs Windows Server R2, but I can find no documentation stating that there should be a difference.

I've been trying to figure this out for a couple weeks, experimenting with different adjustments, and at this point, both I and the server team are out of ideas. Any advice, whether its red flags in my code or just known windows server issues, would be greatly appreciated.

0

There are 0 best solutions below