RequestParams params = new RequestParams("http://192.168.1.160:911/WebService1.asmx/HelloWorld");
// 有上传文件时使用multipart表单, 否则上传原始文件流.
params.setMultipart(true);
params.addBodyParameter("file", new File(AppConfig.DATABASE_PATH + AppConfig.DATABASE_NAME));
x.http().post(params, new CommonCallback<String>() {
@Override
public void onCancelled(CancelledException arg0) {
// TODO Auto-generated method stub
LogUtil.e("onCancelled");
}
@Override
public void onError(Throwable arg0, boolean arg1) {
// TODO Auto-generated method stub
LogUtil.e("onError");
}
@Override
public void onFinished() {
// TODO Auto-generated method stub
LogUtil.e("onFinished");
}
@Override
public void onSuccess(String arg0) {
// TODO Auto-generated method stub
LogUtil.e(arg0);
}
});
第一种接受方式:
[WebMethod]
public void HelloWorld()
{
// System.IO.Stream stream = HttpContext.Current.Request.InputStream;//这是获得的流
var httpFileCollection = HttpContext.Current.Request.Files;
if (httpFileCollection.Keys.Count > 0)
{
HttpPostedFile httpPostedFile = httpFileCollection[0];
httpPostedFile.SaveAs(Server.MapPath(httpPostedFile.FileName));
Context.Response.Write(httpPostedFile.FileName);
Context.Response.End();
}
}
第二种接受方式:
[WebMethod]
public void HelloWorld()
{
System.IO.Stream data = HttpContext.Current.Request.InputStream;//这是获得的流
byte[] buffer = new byte[data.Length];
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath("aa.db"), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}