PDA

View Full Version : [CLOSED] BADRESPONSE Syntax Error



ATLAS
Oct 08, 2013, 11:59 AM
Ext.net.DirectMethod.request({
url: '@(Url.Action("DownloadEvidencePost"))',
failure: function (error) { Ext.Msg.alert('Error', error); },
IsUpload: true,
formId: 'CANDIDATE_EVIDENCE_INFO_FORM_ID',
params:
{
Id: candidate.value,
url: evidenceUrl.value
}
});


controller returns the file contents in response body correctly (Id and Url are valid and file is accessible), failure alerts with BADRESPONSE: Syntax Error
IsUpload true or false makes no difference. Tracing in the controller shows everything is happening ok there and it is returning correctly

any suggestions? I'm pretty much stumped now

ATLAS
Oct 08, 2013, 12:10 PM
Just to update you with the controler code



[HttpPost]
[DirectMethod]
public void DownloadEvidencePost(Guid? Id, string url)
{

if (Id != null && Id != Guid.Empty)
{
var candidate = _myService.RetrieveUser(new Guid(Id.ToString()), true);
var fileName = Path.GetFileName(url);
var fullPath = Path.Combine(
Server.MapPath(
string.Format("~/Content/ClientResources/{0}/UserRecords/{1}/Evidence/",
candidate.Client.DisplayString,
candidate.Username)),
fileName);
//return File(fullPath, contentType, fileName);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fullPath));
Response.TransmitFile(fullPath);
Response.ContentType = "text/plain";
Response.End();

}
}





Ext.net.DirectMethod.request({
url: '@(Url.Action("DownloadEvidencePost"))',
failure: function (error) { Ext.Msg.alert('Error', error); },
IsUpload: true,
formId: 'CANDIDATE_EVIDENCE_INFO_FORM_ID',
params:
{
Id: candidate.value,
url: evidenceUrl.value
}
});


controller returns the file contents in response body correctly (Id and Url are valid and file is accessible), failure alerts with BADRESPONSE: Syntax Error
IsUpload true or false makes no difference. Tracing in the controller shows everything is happening ok there and it is returning correctly

any suggestions? I'm pretty much stumped now

Baidaly
Oct 09, 2013, 1:47 AM
Hello!

To upload file you should use FileContentResult. Look at this thread for more details: http://forums.ext.net/showthread.php?5894

Or you can just use return this.File() : http://forums.ext.net/showthread.php?24882

ATLAS
Oct 10, 2013, 8:33 AM
Neither of these worked - I got around it using window.open!
It works using the response elsewhere so it may be a data issue in what is being passed back (test text file fails too though)

It looks like BADRESPONSE missing character is on the forum a lot with no real solutions


Hello!

To upload file you should use FileContentResult. Look at this thread for more details: http://forums.ext.net/showthread.php?5894

Or you can just use return this.File() : http://forums.ext.net/showthread.php?24882

ATLAS
Oct 10, 2013, 10:01 AM
Neither of these worked - I got around it using window.open!
It works using the response elsewhere so it may be a data issue in what is being passed back (test text file fails too though)

It looks like BADRESPONSE missing character is on the forum a lot with no real solutions

I can get the file download to be correctly handled (browser prompts for save/open) in one situation using a standard controller action. Same use elsewhere fails as above. Also, I tried using an Api controller action. The action returns success. The response looks correct and identical to the working response but the browser never seems to recognise that a file download has taken place!

Daniil
Oct 10, 2013, 2:08 PM
It looks like BADRESPONSE missing character is on the forum a lot with no real solutions

It is quite a common error. I mean many things can be a reason of that.

If you can provide a full test case and exact steps to reproduce it, we would love to investigate it.