function LikesDislikes () {
$.ajax({
url: 'http://gdata.youtube.com/feeds/api/videos/keDZXXDxK1c/ratings',
type:"POST",
data: '<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<yt:rating value="like"/>
</entry>',
headers: {
"Content-Type":"application/atom+xml",
"Content-Length":,
"Authorization":"Bearer ya29.AHES6ZQ59RrQgujZmIjssBdYlwwLVrpCodnirdLROi7-g7U",
"X-GData-Key":"key=AIzaSyAPrtP2Tq4m5WVInCvCWptVAKPhQ4SQNZA",
"GData-Version":"2"
},
// Content-Type:"application/atom+xml",
error: function() { alert("No data found."); },
// contentType: "text/xml",
success: function (response) {
alert('response:' + response);
}
});
}
我如何计算在上述code中的内容长度
?
作为的规范
内容长度实体头域指示的大小 实体主体,以字节的十进制数
The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs
请看起来这个问题字符串的字节长度在JavaScript 。
Basicaly如果您的数据只包含ASCII charachters一切都应该是很容易的。
Basicaly if your data contains only ASCII charachters everything should be quite easy
function LikesDislikes () {
var data = '<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<yt:rating value="like"/>
</entry>';
$.ajax({
url: 'http://gdata.youtube.com/feeds/api/videos/keDZXXDxK1c/ratings',
type:"POST",
data: data,
headers: {
"Content-Type":"application/atom+xml",
"Content-Length": data.length,
"Authorization":"Bearer ya29.AHES6ZQ59RrQgujZmIjssBdYlwwLVrpCodnirdLROi7-g7U",
"X-GData-Key":"key=AIzaSyAPrtP2Tq4m5WVInCvCWptVAKPhQ4SQNZA",
"GData-Version":"2"
},
// Content-Type:"application/atom+xml",
error: function() { alert("No data found."); },
// contentType: "text/xml",
success: function (response) {
alert('response:' + response);
}
});
}