我公司通过HTTP POST向Ariba和Oracle Supplier Networks发送发票。我们遇到了一个问题,我们无法确定它的设置或代码。
以下是代码:
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
send函数类似于SendMime函数,但没有附件(仅限cxml)。此代码在Windows服务和基本GUI测试程序之间共享。
编辑:我得到的错误是:“无法连接到主机。”
事情变得奇怪:
我一直试图解决这个问题几个星期,尝试不同的调整,此时,我和服务器团队都没有想法。任何建议,无论是我的代码中的红旗还是只是已知的Windows服务器问题,都将非常感激。