winService con API
Publicado por Rita (1 intervención) el 11/09/2018 05:40:49
Buenas Tardes
Porfavor su ayudaa, soy nueva enviando archivos a un url, no se porque me muestra este error, estoy revisando el c{odigo varios días y ya no se que más podría ser
"Error en el servidor remoto: (500) Error interno del servidor" y se detiene en esta linea
" Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)"
este es el código:
Public Function Request_PostDocument(ByVal nombrefichero As String, ByVal fichero As String,
ByVal Accesso As String) As String
Dim retVal As String = ""
Dim FilePath As String = pathDefaultProcesados & "\" & nombrefichero
Dim request As HttpWebRequest = CType(WebRequest.Create(urlDocum), HttpWebRequest)
Dim encodedCadena As String = Nothing
Dim cadenaByte As Byte() = New Byte((FilePath).Length - 1) {}
'----------------Headers----------------------------------
request.Headers("Authorization") = "Bearer " + Accesso
'-----------Body------------------------------------
request.Method = "POST"
request.ContentType = "multipart/form-data"
Dim postencoding As ASCIIEncoding = New ASCIIEncoding()
Dim postdata As String = ("Content-Disposition: file; name=" + fichero + "&filename=" + FilePath)
Dim data() As Byte = postencoding.GetBytes(postdata)
request.ContentLength = data.Length
request.ContentLength = cadenaByte.Length
Dim requestStream As Stream = request.GetRequestStream()
requestStream.Write(cadenaByte, 0, cadenaByte.Length)
requestStream.Close()
Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
Return reader.ReadToEnd()
End Using
MsgBox(CType(response, HttpWebResponse).StatusDescription)
End Using
Porfavor su ayudaa, soy nueva enviando archivos a un url, no se porque me muestra este error, estoy revisando el c{odigo varios días y ya no se que más podría ser
"Error en el servidor remoto: (500) Error interno del servidor" y se detiene en esta linea
" Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)"
este es el código:
Public Function Request_PostDocument(ByVal nombrefichero As String, ByVal fichero As String,
ByVal Accesso As String) As String
Dim retVal As String = ""
Dim FilePath As String = pathDefaultProcesados & "\" & nombrefichero
Dim request As HttpWebRequest = CType(WebRequest.Create(urlDocum), HttpWebRequest)
Dim encodedCadena As String = Nothing
Dim cadenaByte As Byte() = New Byte((FilePath).Length - 1) {}
'----------------Headers----------------------------------
request.Headers("Authorization") = "Bearer " + Accesso
'-----------Body------------------------------------
request.Method = "POST"
request.ContentType = "multipart/form-data"
Dim postencoding As ASCIIEncoding = New ASCIIEncoding()
Dim postdata As String = ("Content-Disposition: file; name=" + fichero + "&filename=" + FilePath)
Dim data() As Byte = postencoding.GetBytes(postdata)
request.ContentLength = data.Length
request.ContentLength = cadenaByte.Length
Dim requestStream As Stream = request.GetRequestStream()
requestStream.Write(cadenaByte, 0, cadenaByte.Length)
requestStream.Close()
Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Using reader As StreamReader = New StreamReader(response.GetResponseStream())
Return reader.ReadToEnd()
End Using
MsgBox(CType(response, HttpWebResponse).StatusDescription)
End Using
Valora esta pregunta
0