我正在尝试使用VB.Net将文件上传到Sinatra Web服务,我不知道如何配置任何一端。当我运行VB.Net应用程序时,sinatra总是以代码404响应。这是VB.Net代码,我从另一个SO帖子转换:
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
这是Sinatra代码:
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 "/"
确实显示“到了这里”,但显然没用,因为我需要处理该文件。
显然,我是两个新手,这不是那么难,但我不知道该怎么办。
谢谢。
答案 0 :(得分:0)
好的,对后代来说,这就是我为了让它发挥作用所做的一切。在vb.net代码中,我使用了:
qry_results = wc.UploadFile("http://192.168.9.81:9898/execfqy", "X:\QueryTxtFiles\Query\CDA Curncy_9_1_2011.fqy")
并在sinatra文件中:
post '/execfqy' do
qry_file.write(params[:file][:tempfile].readlines)