I have the next function wich i use to send an xml file named "result.xml" to a webservice, i get an exception at "Dim reqStream As System.IO.Stream = webRequest.GetRequestStream()" wich says "The underlying connection was closed: The remote name could not be resolved"
Can anyone help me with this?
Function MakeHTTPPost(ByVal fullUrl AsString, OptionalByVal bAllowAutoRedirect AsBoolean = True, OptionalByVal iTimeout AsInteger = System.Threading.Timeout.Infinite) AsStringDim webRequest As System.Net.HttpWebRequestDim webResponse As System.Net.HttpWebResponseDim localFile AsString = "result.xml"Try'Create an HttpWebRequest with the specified URL.
webRequest =
CType(System.Net.WebRequest.Create(fullUrl), System.Net.HttpWebRequest)webRequest.ContentType = "text/xml"
webRequest.Method = "POST"
webRequest.AllowAutoRedirect = bAllowAutoRedirect
'webRequest.MaximumAutomaticRedirections = 50webRequest.Timeout = iTimeout
Dim reqStream As System.IO.Stream = webRequest.GetRequestStream()Dim wrtr As System.IO.StreamWriter = New System.IO.StreamWriter(reqStream)'Open the local fileDim rdr As System.IO.StreamReader = New System.IO.StreamReader(localFile)'loop through the local file reading each line 'and writing to the request stream bufferDim inLine AsString = rdr.ReadLine()While (inLine <> "")wrtr.WriteLine(inLine)
inLine = rdr.ReadLine()
EndWhilerdr.Close()
wrtr.Close()
'Send the request and wait for a response.TrywebResponse =
CType(webRequest.GetResponse(), System.Net.HttpWebResponse)SelectCase (webResponse.StatusCode)Case System.Net.HttpStatusCode.OK'read the content from the responseDim responseStream As System.IO.Stream = webResponse.GetResponseStream()Dim responseEncoding As System.Text.Encoding = System.Text.Encoding.UTF8' Pipes the response stream to a higher level stream reader with the required encoding format. Dim responseReader AsNew System.IO.StreamReader(responseStream, responseEncoding)Dim responseContent AsString = responseReader.ReadToEnd()Return responseContentCase System.Net.HttpStatusCode.Redirect, System.Net.HttpStatusCode.MovedPermanentlyThrowNew System.Exception(String.Format("Unable to read response content. URL has moved. StatusCode={0}.", webResponse.StatusCode))Case System.Net.HttpStatusCode.NotFoundThrowNew System.Exception(String.Format("Unable to read response content. URL not found. StatusCode={0}.", webResponse.StatusCode))CaseElseThrowNew System.Exception(String.Format("Unable to read response content. StatusCode={0}.", webResponse.StatusCode))EndSelectCatch we As System.Net.WebExceptionThrowNew System.Exception("Unable to execute URL.", we)FinallyIf (Not IsNothing(webResponse)) ThenwebResponse.Close()
EndIfEndTryCatch e As System.ExceptionMsgBox("Unable to execute URL2. - " & e.Message)
EndTryEndFunction