Haskell-使用Haskell上传文件(POST方法)

时间:2019-07-14 12:06:20

标签: haskell servant

我想复制这个curl命令

class MyClass
{
    private $arr = array();

    public function __construct()
    {
        $var = function(){return 123;};

        $this->setArrElm('New', $var); 
    }

    private function setArrElm($name, $val) //<-- mixed
    {
        if(is_callable($val)){
            //pass functions (as a string) or arrays or closures(executable classes with __invoke)
            $val = call_user_func($val);
        }
        $this->arr[$name] = $val;
        print_r($val);
    }
}

new MyClass;

我项目中的许多编码都是通过Servant DSL完成的,所以我虽然应该是理想的解决方案

curl --request POST \
'https://www.someapi.com/upload/textfile?id=someid' \
--header 'Authorization: someauthcode' \
--header 'Accept: application/json' \
--header 'Content-Type: appication/octet-stream' \
--data '{"owner":"name"}' \
--data @somefile.txt

但这不起作用。

所以我想问,什么是最好的选择?

编辑:忘记添加错误-

baseURL = BaseUrl Https "www.someapi.com" 443 ""

uploadAPI :: Proxy Upload                                                                                                    
uploadAPI = Proxy   

type Upload = "upload" :> ... :> ReqBody '[OctetStream] ByteString :> Post '[OctetStream] ()

uploadImage :: Proxy Upload
uploadImage = Proxy

0 个答案:

没有答案