【发布时间】:2010-08-10 11:39:45
【问题描述】:
我有一个简单的网络服务,我想将文件上传到。问题是我需要 json 格式的响应。
根据我的经验,为了在 Json 中获得响应,我的请求必须具有“应用程序/json”的内容类型。但是,文件上传当然不能这样,因为内容类型必须是“multipart/form-data”。
在我的 Json 中,我想返回一个显示是否成功的值和一个文件名。
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public TyoeOfSomeObject UploadFile()
{
// Get the file from the context and do something with it
HttpPostedFile httpPostedFile = HttpContext.Current.Request.Files[0];
// Return either a string or an object to serialise with the required values
return SomeObject;
}
【问题讨论】:
标签: asp.net web-services json file-upload