vala 异步http请求示例代码

代码语言:vala

所属分类:通讯

代码描述:vala 异步http请求示例代码

代码标签: 请求 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

class AsyncDemo {

    private MainLoop loop;

    public AsyncDemo (MainLoop loop) {
        this.loop = loop;
    }

    public async void http_request () throws Error {
        try {
            var resolver = Resolver.get_default ();
            var addresses = yield resolver.lookup_by_name_async ("www.baidu.com");
            var address = addresses.nth_data (0);
            print ("(async) resolved www.google.com to %s\n", address.to_string ());

            var socket_address = new InetSocketAddress (address, 80);
            var client = new SocketClient ();
            var conn = yield client.connect_async (socket_address);
            print ("(async) connected to www.google.com\n");

            var message = "GET / HTTP/1.1\r\nHost: ww.........完整代码请登录后点击上方下载按钮下载查看

网友评论0