0
我想使用VB.Net上傳文件到Sinatra Web服務,我不知道如何配置任何一端。當我運行VB.Net應用程序,西納特拉總是用代碼404響應下面是VB.Net代碼,這是我從另一個SO後轉換:試圖使用vb.net上傳文件到sinatra
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim responseData As String = ""
Dim rdr As FileStream = New FileStream("X:\QueryTxtFiles\Query\CDA Curncy_9_1_2011.fqy", FileMode.Open)
Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://finqueryserver:9898"), HttpWebRequest)
req.Method = "POST" ' you might use "POST"
req.ContentLength = rdr.Length
req.AllowWriteStreamBuffering = True
Dim reqStream = DirectCast(req.GetRequestStream(), Stream)
Dim inData(rdr.Length) As Byte
' Get data from upload file to inData
Dim bytesRead As Integer = rdr.Read(inData, 0, rdr.Length)
' put data into request stream
reqStream.Write(inData, 0, rdr.Length)
rdr.Close()
Try
req.GetResponse()
Catch ex As Exception
responseData = "An error occurred: " & ex.Message
End Try
' after uploading close stream
reqStream.Close()
End Sub
這裏是西納特拉代碼:
require 'rubygems'
require 'sinatra'
post '/:name/:filename' do
puts "got here"
begin
name = params[:name]
rescue
name = "no name"
end
begin
filename = params[:filename]
rescue
filename = "no filename"
end
end
(我從來沒有看到「來到這裏」。)Sinatra代碼是基於使用cURL的教程,我不是。我也試着
post "/:filename'
這給404也和簡單
post "/"
這確實顯示「來到這裏」,但顯然是無用的,因爲我需要處理的文件。
很明顯,我是兩個新手,這不可能很難,但我不知道該怎麼做。
謝謝。