如何Part
与[(ByteString, ByteString)]
(普通表单输入)结合?
partFile :: Text -> FilePath -> Part
它们都是Postable
类型类http://hackage.haskell.org/package/wreq-0.5.3.2/docs/Network-Wreq-Types.html#t:Postable的一部分
我猜猜这是可以用镜头组合器完成的事情吗?
下面是我发送两个请求的完整代码 - 一个带有发布表单字段 - 另一个带有文件上传。
应用程序.cabal
cabal-version: 1.12
name: app
version: 0.1.0.0
author: CabalSaneDefault
maintainer: nobody
license: BSD3
build-type: Simple
executable app-test
main-is: Test.hs
other-modules:
Paths_app
hs-source-dirs:
src
build-depends:
base
, bytestring
, lens
, wreq
default-language: Haskell2010
src/Test.hs
{-# Language OverloadedStrings #-}
module Test where
import Network.Wreq
import Control.Lens
import Data.ByteString (ByteString)
import Data.ByteString.Lazy.Char8 (putStrLn)
import qualified Network.Wreq.Session as S
main :: IO ()
main = do
let rootUrl = "http://localhost:80"
print "test"
sess <- S.newSession
x <- S.customHistoriedPayloadMethodWith
"POST"
defaults
sess
(rootUrl ++ "/post")
([("test","chris"), ("test2", "chris2")] :: [(ByteString, ByteString)])
Data.ByteString.Lazy.Char8.putStrLn $ (x ^. hrFinalResponse ^. responseBody)
print "--------------------------------------------------"
x' <- S.customHistoriedPayloadMethodWith
"POST"
defaults
sess
(rootUrl ++ "/post")
(
(partFile "" "app.cabal")
)
Data.ByteString.Lazy.Char8.putStrLn $ (x' ^. hrFinalResponse ^. responseBody)