在 vb.net 中通过post方法将文件发送到服务器,并在服务器端接收文件并将其保存在文件夹中

send file to the server by postmethod in vb.net and at the server side receiving it and saving it in folder

提问人:Prakash 提问时间:11/9/2023 更新时间:11/9/2023 访问量:20

问:

但它没有收到文件

Public Sub UploadFile(filePath As String, url As String)         
Using httpClient As New HttpClient             
Using fileStream As New FileStream(filePath, FileMode.Open, FileAccess.Read)                 
Dim fileContent As StreamContent = New StreamContent(fileStream)                 
Dim formContent As MultipartFormDataContent = New MultipartFormDataContent()  
formContent.Add(fileContent, "file", Path.GetFileName(filePath))                 
Dim response As HttpResponseMessage = httpClient.PostAsync(url, formContent).Result
End Using        
End Using   
End Sub

已使用 URL 和文件路径调用此方法

在 CS 文件中处理该文件上传,例如

if (Request.HttpMethod == "POST")   
{       
if (Request.Files.Count > 0)      
{             HttpFile uploadedFile = Request.Files[0];        
  string fileName = Path.GetFileName(uploadedFile.FileName);       
  string filePath = Server.MapPath("~/uploads/" + fileName);                
  uploadedFile.SaveAs(filePath);       
  }  }
asp.net vb.net Web 表单

评论


答: 暂无答案