Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell wreq如何将文件上载与post表单字段相结合?_Haskell_Wreq - Fatal编程技术网

Haskell wreq如何将文件上载与post表单字段相结合?

Haskell wreq如何将文件上载与post表单字段相结合?,haskell,wreq,Haskell,Wreq,如何将部分与[(ByteString,ByteString)]组合(普通表单输入) 它们都是Postabletypeclass的一部分 我猜这是用镜头组合器可以做到的 下面是我发送两个请求的完整代码,一个带有post表单字段,另一个带有文件上传 应用阴谋集团 cabal-version: 1.12 name: app version: 0.1.0.0 author: CabalSaneDefault maintainer: nob

如何将
部分
[(ByteString,ByteString)]
组合(普通表单输入)

它们都是
Postable
typeclass的一部分

我猜这是用镜头组合器可以做到的

下面是我发送两个请求的完整代码,一个带有post表单字段,另一个带有文件上传

应用阴谋集团

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)
{-#语言重载字符串}
模块测试在哪里
导入网络.Wreq
进口管制.镜头
导入Data.ByteString(ByteString)
导入Data.ByteString.Lazy.Char8(putStrLn)
将合格的Network.Wreq.Session作为S导入
main::IO()
main=do
让rootUrl=”http://localhost:80"
打印“测试”
sess通过testring
创建
部分
,然后我们可以发布
[Part]
,因为它是
Postable
的一个实例

  x' <- S.customHistoriedPayloadMethodWith
    "POST"
    defaults
    sess
    (rootUrl ++ "/post")
    (
      [
        (partFile "" "app.cabal")
      , partBS "test" "chris"
      , partBS "test2" "chris2"
    ]
    )
x'通过testring
创建
部分
,然后我们可以发布
[Part]
,因为它是
Postable
的一个实例

  x' <- S.customHistoriedPayloadMethodWith
    "POST"
    defaults
    sess
    (rootUrl ++ "/post")
    (
      [
        (partFile "" "app.cabal")
      , partBS "test" "chris"
      , partBS "test2" "chris2"
    ]
    )
x'