Как отправить изображение с помощью метода web api для разъединения с клиентской машины.
Привет
У меня есть метод в моем веб - api,который принимает 4 параметра as-stream,string,int, long
как вызвать метод webapi POST из клиента .
я пробовал классы webclinet или webrequest
но я получаю ошибку 404-файл не найден всякий раз, когда пытаюсь выполнить
wc.UploadData(URL, "POST", byteData) or Dim response As HttpWebResponse = request.GetResponse()
Любое предложение будет высоко оценено .
Что я уже пробовал:
<pre> Imports System Imports System.Text Imports System.Collections Imports System.Collections.Generic Imports System.Data Imports System.Net Imports System.Net.Security Imports System.IO Imports System.Net.HttpListener Imports System.Net.Http.Headers Imports System.Security.Cryptography Imports System.Security Imports System.Web Module Module1 Function CertificateValidationCallBack( _ ByVal sender As Object, _ ByVal certificate As X509Certificates.X509Certificate, _ ByVal chain As X509Certificates.X509Chain, _ ByVal sslPolicyErrors As SslPolicyErrors _ ) As Boolean Return True End Function Sub Main() Dim fileData As Byte() = File.ReadAllBytes("D:\pic.jpg") Dim URL As String = "MY_URL" Dim imgstream As Stream = New MemoryStream(fileData) Dim reader As StreamReader = New StreamReader(imgstream) Dim text As String = reader.ReadToEnd() Dim request As HttpWebRequest = WebRequest.Create(URL) Dim wc As WebClient = New WebClient() Dim BasicAuth As String = "Basic sdsddsaaa" wc.Headers.Add("Authorization", BasicAuth) request.Headers.Add("Authorization", BasicAuth) ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack) request.ContentType = "application/x-www-form-urlencoded" request.Method = "POST" Dim data As StringBuilder = New StringBuilder() data.Append("stream=" + text) data.Append("&filename=" + "pic.jpg") data.Append("&ulpMembershipId=" + "1234567") data.Append("&mobileNumber=" + "2222222") data.Append("&createdBy=" + "aaaaa") Dim data1 As String = System.Uri.EscapeDataString(data.ToString()) Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(data1.ToString()) ' Set the content length in the request headers request.ContentLength = byteData.Length ' Write data Dim postStream As Stream = request.GetRequestStream() postStream.Write(byteData, 0, byteData.Length) wc.UploadData(URL, "POST", byteData) Dim response As HttpWebResponse = request.GetResponse() ' Get the response stream Dim reader1 As StreamReader = New StreamReader(response.GetResponseStream()) ' Console application output Dim output As String = reader1.ReadToEnd() End Sub End Module