这个问题搞了好多天了,网上找了好多,都是一些半成品, 终于整明白,希望给跟我一样的新手们有,帮助直接上代码
c#端
android端代码
HttpURLConnection con;
URL url;
String httpUrl=http://192.168.1.124/Upload.ashx;//此处是自己的服务接口
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();
}