2011-10-23 2 views
2

나는이 같은 자바 스크립트 코드가 있습니다Request.QueryString [ "path"]가 모든 + 기호를 공백으로 변환하는 이유는 무엇입니까?

function OnRequestComplete(result) { 
     // Download the file 
     //Tell browser to open file directly 
     alert(result); 
     var requestImage = "Handler.ashx?path=" + result; 
     document.location = requestImage; 
} 

및 Handler.ashx 코드는 다음과 같다 :

public void ProcessRequest(HttpContext context) 
{ 
    Context = context; 
    string filePath = context.Request.QueryString["path"]; 
    filePath = context.Server.MapPath(filePath); 
} 

은 여기서 filePath에서 우리는 (대신 공간) 어떤 + 표시가 없습니다.
이 문제를 어떻게 해결할 수 있습니까?
Request.QueryString [ "path"]가 모든 + 기호를 공백으로 변환하는 이유는 무엇입니까?

+0

확인이 답변 : http://stackoverflow.com/questions/123994/querystring-malformed-after-urldecode/124027#124027 –

+0

의 QueryStrings 자신의 구문과 예약 문자가 있습니다. 직접 파일 이름을 인코딩하십시오. –

답변

4

쿼리 문자열을 올바르게 인코딩하면 +이되고 +%2B이됩니다. 디코딩 과정은 그 반대입니다. 따라서 +이 공간으로 변환됩니다.

문제는 쿼리 문자열이 encode이 아니므로 올바르게 디코딩되지 않는다는 것입니다.

var requestImage = "Handler.ashx?path=" + encodeURIComponent(result); 
+0

답변을 주셔서 감사합니다/나는 그 쿼리 문자열을 자바 스크립트로 인코딩해야합니까? 방법? – MoonLight

+0

답변이 업데이트되었습니다. –