2012-12-23 11 views
6

私は、ダーツのカールのような機能を得る最良の方法を探しています。たとえば、google.comのウェブコンテンツを取得して出力する方法を例として挙げます。ダートのカールのような機能

私はthe shell as shown hereを経由して、それを呼び出すことができることがわかった、しかしそれは理想的なアプローチのように見えるしていません:

import 'dart:io'; 

main() { 
    var f = new File(new Options().executable); 
    Process.start('curl', 
       ['--dump-header', '/tmp/temp_dir1_M8KQFW/curl-headers', '--cacert', 
       '/Users/ager/dart/dart/third_party/curl/ca-certificates.crt', '--request', 
       'POST', '--data-binary', '@-', '--header', 'accept: ', '--header', 'user-agent: ' , 
       '--header', 'authorization: Bearer access token', '--header', 
       'content-type: multipart/form-data', '--header', 
       'content-transfer-encoding: binary', '--header', 
       'content-length: ${f.lengthSync()}', 'http://localhost:9000/upload']).then((p) { 
    f.openInputStream().pipe(p.stdin); 
    p.stdout.pipe(stdout); 
    p.stderr.pipe(stderr); 
    p.onExit = (e) => print(e); 
    }); 
} 

私はまた、APIを見て、ここで私を助けるために何かを見つけることができませんでした。

答えて

8

ダートIOライブラリには、基本的にあなたが探しているものがHttpClientと付属しています。ただし、おそらくhttp Pubパッケージを代わりに使用する必要があります。ちょうどその

dependencies: 
    http: any 

実行pub installと::

import 'package:http/http.dart' as http; 

main() { 
    http.read('http://google.com').then((contents) { 
    print(contents); // Here we output the contents of google.com. 
    }); 
} 
あなたの依存関係ファイルに追加します
関連する問題