Avhttp/file_upload.hpp示例调用失败


#1

在avhttp下的file_upload.hpp文件里发现了示例代码,花了一下午移到项目里,结果发现错误,代码如下:

boost::asio::io_service io;
 	avhttp::file_upload upload(io);
 	avhttp::file_upload::form_args fields;
 	fields["username"] = "Cai";
 	boost::system::error_code ec;
 	upload.open(as_Url, "cppStudy.tar.bz2",
 		"file", fields, ec);
 	if (ec)
 	{
 		// 处理错误.
 	}
 	// 开始上传文件数据.
 	avhttp::default_storge file;
	file.open("d:\\Trace.ini", ec);
 	if (ec)
 	{
 		// 处理错误.
 	}

 	boost::array<char, 1024> buffer;
 	while (!file.eof())
 	{
 		int readed = file.read(buffer.data(), 1024);
 		boost::asio::write(upload, boost::asio::buffer(buffer, readed), ec);
 		if (ec)
 		{
 			// 处理错误.
 		}
 	}
 	upload.write_tail(ec);
 	if (ec)
 	{
 		// 处理错误.
 	}

相对于示例只是修改了一个地址和文件的路径,错误为:


Microsoft Visual C++ Runtime Library

Assertion failed!

Program: D:\test90.exe File: d:\avh…/socket_type.hpp Line: 723

Expression: instantiated()

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)

中止(A) 重试® 忽略(I)

请问大侠怎么回事?


#2

请问运行到哪一行出错的? 有更详细的信息吗? 运行example/imagebin.cpp的示例会有问题吗?


#3
boost::asio::write(upload, boost::asio::buffer(buffer, readed), ec);

这一行出的错


#4

我在项目中也用了file_upload 是照着Imagebin.cpp写的 没有问题


#5

仔细分析了下,应该是你抄示例的时候,没处理error_code,示例中是免去了error_code的处理。