ASP.NET webAPI< - > Dojo上传者的响应格式错误 [英] ASP.NET webAPI <--> Dojo uploader response format is wrong
问题描述
我有使用dojo上传文档的问题。
我使用dojox / form / Uploader来上传一个文件,不支持模式。上传后,以特殊格式响应服务器。上传者只有在我发送时才有效:
i have a problem with uploading documents with dojo. I´m using the dojox/form/Uploader to upload a file withiframe mode. After uploading there is a response from the server in a special format. The uploader only works when i send it like this:
服务器:'{name:file.png,file:filename,type :form-data}'
Server: '{"name":"file.png","file":"filename","type":"form-data"}'
但答案是:
客户端:'{\name \:\ .png \,\file\:\filename \,\type\:\form-data\}'
But the answer is: Client: "'{\"name\":\"file.png\",\"file\":\"filename\",\"type\":\"form-data\"}'"
所以我认为有两种可能的方法来解决这个问题:
So i think there are two possible ways to solve this problem:
A。修复它在客户端
B.修复它在服务器端
A. Fixing it on the client side B. Fixing it on the server side
我找不到一个解决方案B.我使用ASP.NET webAPI并创建这样的回复:
I could not find a solution for B. I´m using ASP.NET webAPI and create the reponse like that:
Dim msg = "<textarea>'{" + Chr(34) + "name" + Chr(34) + ":" + Chr(34) + fileName + Chr(34) + "," + Chr(34) + "file" + Chr(34) + ":" + Chr(34) + returnData.Item1 + Chr(34) + "," + Chr(34) + "type" + Chr(34) + ":" + Chr(34) + returnData.Item3 + Chr(34) + "}'</textarea>"
Dim response = Request.CreateResponse(Of String)(HttpStatusCode.Created, msg)
response.Content.Headers.ContentType = New MediaTypeHeaderValue("text/html")
Return response
看起来很奇怪,但答案必须由html标签包含,内容是json。
Looks weird but the answer has to be enclosed by a html tag, the content is json.
也许有一种方法可以告诉webAPI不要将这些额外的斜线放在响应中?
我放弃了,决定在客户端执行。
Maybe there is a way to tell webAPI not to put those extra slashes into the response ? I gave up and decided to do it on the client side.
问题是,我不得不更改dojo库中的iframe.js文件,非常糟糕。
Problem is, i had to change the iframe.js file in the dojo library which is very bad.
推荐答案
我自己解决了这个问题,这里是服务器端解决方案:
I solved the problem by myself, here is the server side solution:
json = System.Web.HttpUtility.HtmlEncode(json)
Dim msg = "<textarea>" + json + "</textarea>"
dojo文件上传器现在可以理解响应,并可以正确解析。
The dojo file uploader now understands the response and can parse it correctly.
这篇关于ASP.NET webAPI< - > Dojo上传者的响应格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!