2011-12-13 47 views
0

我必須使用UTF-8發送此請求,但它不起作用。UTF-8錯誤的HTTP請求?

如何使用UTF-8格式發送此請求?

var request = new ActiveXObject("Microsoft.XMLHTTP"); 

    request.onreadystatechange = function() 
    { 
     if (request.readyState == 4) 
     { 
      // ret 
     } 
    } 

    httpUrl="/ISV/AddCustomerWebSite/Default.aspx?"; 
    httpUrl = httpUrl + "vendorID="+paramsList[0]+ 
       "&title="+paramsList[1]+ 
       "&planTypeID=" +paramsList[2]; 

    request.open("GET", httpUrl); 
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; Charset=utf-8"); 
    request.send(null); 
+1

在將它們添加到URL之前,您需要使用encodeURIComponent()對您的參數值進行編碼。 – Pointy

+1

_你有什麼錯誤?_ – SLaks

+0

encodeURIComponent()保存我thx – Mennano

回答

0

這裏是我的評論的問答形式:該錯誤可能有事情做與不被URL編碼的參數值:

httpUrl = httpUrl + "vendorID=" + 
    encodeURIComponent(paramsList[0]) + 
    "&title=" + 
    encodeURIComponent(paramsList[1]) + 
    "&planTypeID=" + 
    encodeURIComponent(paramsList[2]); 

該編碼將(幾乎肯定)是未做過透明地由你的服務器端框架。