2016-04-07 21 views
6

どうすればいいですか?GETPOST HTTPリクエストですか?私はソケット解決策を見つけましたが、それはすべてですか?HTTPリクエストではないソケットWebリクエスト - D

string host = "google.com"; 
ushort port = 80; 

Socket listener = new TcpSocket; 
    assert(listener.isAlive); 
    listener.blocking = false; 

listener.connect(new InternetAddress(host, port)); 

char[] msg; 
char[] req = cast(char[]) "GET /search.php HTTP/1.1\r\nHost: google.com\r\n\r\n"; 

listener.send(req); 

答えて

6

std.net.curlをご覧ください。それはgetpostのメソッドがあります。

import std.net.curl; 

auto content = get("d-lang.appspot.com/testUrl2"); 
// -- 
auto content = post("d-lang.appspot.com/testUrl2", [1,2,3,4]); 
2

カールは、紛れもなく良い解決策です。しかし、これはあなたのプロジェクトに新たな依存関係を追加するでしょう。あなたが取り組んでいるプロジェクトの種類によって、Adam Ruppeのarsdモジュール、特にhttpモジュール(彼はhttp2でも同様に働いています) - https://github.com/adamdruppe/arsd/blob/master/http.dを使用することをお勧めします。または、おそらくフレームワークが必要な場合は、vibe.dもHTTPクライアントを持っているため、最良のオプション(http://vibed.org)です。 2つのvibe.dに関連したWeb開発指向の本がありますが、それは次のページに記載されています:http://vibed.org/tutorials

関連する問題