![](/img/trans.png)
[英]How can i passing two parameters to restful web service using http post? UnrecognizedPropertyException: Unrecognized field , not marked as ignorable
[英]How can I post FileInfo to a web service using Yesod and Http-Conduit?
我正在使用默認的Yesod腳手架項目。
我創建了一個顯示上傳文件的簡單表單的頁面。
(該表單可能會使用Javascript在客戶端上創建。)
為簡潔起見,表單只有一個文件輸入:
<form method="post" action=@{UploadR}>
<input type="file" name="myfile">
<button type="submit">
我的目標是處理表單數據,然后將文件上傳到Web服務。
我處理表單沒有問題,我擔心的是與Web服務進行交互。
例如,給定以下Yesod處理程序:
postUploadR :: Handler Html
postUploadR = do
mgr <- fmap httpManager getYesod
fi <- runInputPost $ ireq fileField "myfile"
let fSource = fileSource fi
fName = fileName fi
req <- parseUrl "http://webservice/upload"
let areq = req { method = methodPost
, requestBody = requestBodySourceChunked fSource
}
res <- httpLbs areq mgr
defaultLayout $ do
setTitle "file uploaded"
[whamlet|
<h3> Success
<p> You uploaded #{fName}.
|]
webservice返回錯誤: fail post content-length
,但其他所有內容都按預期工作。 也許服務器不支持分塊請求體?
我認為你對chunked request body的猜測是正確的。 你需要做的是:
requestBodySource
並提供文件長度及其內容。 幸運的是, sinkCacheLength函數可以很容易地處理步驟(1)和(2)。 你最終會得到類似的東西:
(fSize, fSource) <- fileSource fi $$ sinkCacheLength
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.