图像使用c#web服务从Android应用程序上传到服务器
我想使用c#web服务将图像上传到IIS服务器。 我已经为此编写了Web方法,如下所示:
[WebMethod] public string UploadFile(byte[] f, string fileName) { try { MemoryStream ms = new MemoryStream(f); FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath ("~/TransientStorage/") +fileName, FileMode.Create); ms.WriteTo(fs); ms.Close(); fs.Close(); fs.Dispose(); return "OK"; } catch (Exception ex) { // return the error message if the operation fails return ex.Message.ToString(); } }
这里web方法将参数作为byte []。我已经将sdcard图像转换为byte []但是当我将它作为URL参数传递时它不起作用。我也试过将byte []数组转换为base64 strig仍然没有用。
任何人都可以告诉我如何使用c#web服务将图像上传到IIS服务器。
您需要将其POST
到服务器,设置内容类型并将字节数组包括为post的主体。
请参阅此处,了解从C#
进行此操作的示例, 此处是Android的示例。
- www.text没有显示android中的完整数据
- 如何使用visual studio和xamarin关闭活动android
- Android TextView defStyle参数被忽略了吗?
- 如何从post async http请求下载数据时将数据加载到reclyerview中
- 在跨平台xamarin项目(ios和android)中使用c#从查询列表中检索数据时面临参数exception错误
- 使用C#的c2dm服务器
- MvvmCross; 如何从另一个ViewModel RaisePropertyChange
- 在PushSharp 4.0中构建GCM消息
- Xamarin FindViewById返回null