用asp.net做的webservice,客户端是android, android端要上传头像(目前android端是通过http流的方式传输过来的),
并且保存到服务器上面,我不知道服务器需要如何去处理,能贴出代码吗。有人说跟webservice没有关系,直接用ashx文件处理,但是我想知道,怎么处理呢,能贴出代码吗这个问题,已经发了好几天,也好几便了,一直没人解决,我都已经没有分了,只有这么点了,请高手帮我解决吧。我愁呀android端的代码是这样的:HttpURLConnection con;
URL url;
String httpUrl="http://192.168.0.105/TUISONG/Service.asmx";
InputStream in;
byte[] buf=new byte[1024];

try {
in=new FileInputStream(new    File(Environment.getExternalStorageDirectory()+"/treemenu.jpg"));
url=new URL(httpUrl);
con=(HttpURLConnection)url.openConnection();
con.setConnectTimeout(20000);
        con.setReadTimeout(12000);
            con.setRequestMethod("POST");
            con.setDoOutput(true);
            con.setDoInput(true);
            
            OutputStream osw = con.getOutputStream();
            while(in.read(buf)!=-1){
             osw.write(buf);
            }
osw.flush();
osw.close();
in.close();
            int code = con.getResponseCode();
            System.out.println("code:"+code);
            
} catch (Exception e) {
e.printStackTrace();
}

解决方案 »

  1.   

    思路就是,
    你得到的文件是
    Request.InputStream;
    把这个存成文件就可以了
      

  2.   

    恩。 我现在是这么做的
    public void ProcessRequest(HttpContext context)
        {
            
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";        string uploadPath = HttpContext.Current.Server.MapPath(WebCommon.GetClientImagePath());
            if (!System.IO.Directory.Exists(uploadPath))
            {
                System.IO.Directory.CreateDirectory(uploadPath);
            }        
            System.IO.Stream stream = context.Request.InputStream;//这是你获得的流         byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);     //将流的内容读到缓冲区         System.IO.FileStream fs = new System.IO.FileStream(uploadPath + "test.jpg", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
            fs.Write(buffer, 0, buffer.Length);
            fs.Flush();
            fs.Close();
      
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }    
      

  3.   

    stream.Position = 0;
    stream.Read(buffer, 0, buffer.Length);
      

  4.   

    public void ProcessRequest(HttpContext context)
        {
            
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";        string uploadPath = HttpContext.Current.Server.MapPath(WebCommon.GetClientImagePath());
            if (!System.IO.Directory.Exists(uploadPath))
            {
                System.IO.Directory.CreateDirectory(uploadPath);
            }        
            System.IO.Stream stream = context.Request.InputStream;//这是你获得的流         byte[] buffer = new byte[stream.Length];
            
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);     //将流的内容读到缓冲区         System.IO.FileStream fs = new System.IO.FileStream(uploadPath + "test.jpg", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
            fs.Write(buffer, 0, buffer.Length);
            fs.Flush();
            fs.Close();
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }    已经加了那句话,还是不行。
      

  5.   

    String httpUrl="http://192.168.0.105/TUISONG/Service.asmx";
    这句话应该是指向webserver的*.ashx文件,楼主不厚道,不上解决方法