0
我有问题,使用C#.NET 这里从Android应用服务器上传照片
于Android上传图像到服务器是到目前为止我的代码...: 客户端(安卓)使用C#.NET
EDIT
class ImageUploadTask extends AsyncTask<Void, Void, String> {
private String webAddressToPost = "http://myIP/Glasses/api/Photo/";
@Override
protected String doInBackground(Void... params) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(webAddressToPost);
MultipartEntity entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
byte[] file = Base64.encode(data, Base64.DEFAULT);
string filecode = new String(file);
entity.addPart("uploaded", new StringBody(filecode));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost, localContext);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse = reader.readLine();
return sResponse;
} catch (Exception e) {
// something went wrong. connection with the server error
}
return null;}
我有在服务器端的一些问题(MVC C#)
[HttpPost]
public string SetPhoto([FromBody] string imageSource)
{
string bytes = imageSource;
return "success";
}
一个d这是我WebApiConfig
config.Routes.MapHttpRoute(
name: "SetPhoto",
routeTemplate: "api/{controller}/{imageSource}");
*“该应用程序没有保存图像,只是一直崩溃”*任何特定的错误/例外? –