图像使用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的示例。