小编Dev*_*977的帖子

在 Flutter 中使用 Cookie 发布请求

我正在尝试将 Cookie 添加到我的请求中:

在这里我收到csrftoken一个GET请求:

 Future<String> getCsrftoken() async{
       var response = await http.get(Uri.encodeFull('http://test/accounts/login/'));
       var csrftoken = response.headers.remove('set-cookie').substring(10,74); //csrf 
       64 chars
       return csrftoken;
    }
Run Code Online (Sandbox Code Playgroud)

在这里,我尝试使用包Dio执行POST( application/x-www-form-urlencoded) 请求 。

getSessionId() async {
  var csrf = await getCsrftoken();
  var cj = new CookieJar();
  List<Cookie> cookies = [new Cookie("csrftoken", csrf)];
  cj.saveFromResponse(Uri.parse("http://test/accounts/login/"), cookies);
  List<Cookie> results = cj.loadForRequest(Uri.parse("http://test/accounts/login/"));
  var dio = new Dio(new Options(
      baseUrl: "http://test/accounts/login/",
      connectTimeout: 5000,
      receiveTimeout: 100000,
      // 5s
      headers: {
      },
      contentType: ContentType.JSON,
      // …
Run Code Online (Sandbox Code Playgroud)

cookies post request dart flutter

2
推荐指数
1
解决办法
9116
查看次数

Flutter-处理POST请求中的状态码302

我正在尝试使用postFlutter 发送带有DIO包装的请求。

这是请求:

getSessionId() async {

  var csrf = await getCsrftoken();

  var dio = new Dio(new Options(
      baseUrl: "http://xxxxxxx/accounts/login/",
      connectTimeout: 5000,
      receiveTimeout: 100000,
      // 5s
      headers: {
        'Cookie': "csrftoken=" + csrf
      },
      contentType: ContentType.JSON,
      // Transform the response data to a String encoded with UTF8.
      // The default value is [ResponseType.JSON].
      responseType: ResponseType.PLAIN
  ));

  var response;
  response = await dio.post("http://xxxxxxx/accounts/login/",
    data: {
      "username": "xxxxx",
      "password": "xxxxx",
      "csrfmiddlewaretoken" : csrf
    },
    options: new Options(
        contentType: ContentType.parse("application/x-www-form-urlencoded")),
  ); …
Run Code Online (Sandbox Code Playgroud)

post request http-status-code-302 dart flutter

2
推荐指数
3
解决办法
4719
查看次数

如何在Flutter中反转ListView

我实现了listview,可以从获取数据json

我遵循了这个实现。

我该如何反转此列表视图的顺序?(第一个元素应该变成最后一个元素,等等)。

listview future list dart flutter

2
推荐指数
4
解决办法
4340
查看次数

由于ec2服务器中的EnvironmentError,无法安装软件包

我在我工作的amazon ec2 linux服务器上输入以下内容.(已激活ENV)

pip install pillow
Run Code Online (Sandbox Code Playgroud)

收到此错误:

Could not install packages due to an EnvironmentError: 
[Errno 13] Permission denied: '/home/ec2-user/env/lib64/python3.5/site-packages/Pillow-5.1.0.dist-info'. 
Consider using the `--user` option or check the permissions.
Run Code Online (Sandbox Code Playgroud)

如果我使用--user i get:无法执行'--user'安装.用户站点包在此virtualenv中不可见.

linux django pip amazon-ec2 server

1
推荐指数
1
解决办法
3136
查看次数