我能够在命令行上使用以下命令来使用REST服务。curl的REST调用相当于jQuery AJAX
卷曲-v --user UNAME:通-H “接受:应用程序/ XML” http://xyz.abc.def
什么是AJAX等价的一样吗?如何在ajax调用中提供用户名:密码?我不UNAME当前功能:密码是:
function getData() {
var name, code;
var serviceURL = "http://xyz.abc.def";
$.support.cors = true;
$.ajax({
type: "GET",
dataType: "xml",
crossDomain: true,
url: serviceURL,
success: function(data) {
$(data).find("VariableTree Variable").each(function() {
code = $(this).find("Code").text();
name = $(this).find("Name").text();
$("#variable").append("<option data-value='" + code + "'>" + name + "</option>")
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(errorThrown);
}
});
}
PS:服务是由Spring Security的
如果服务使用sprint安全保护,那么您在curl命令中使用basic auth,否则我不会看到curl命令是如何工作的。 – abc123
您需要了解[基本认证](http://en.wikipedia.org/wiki/Basic_access_authentication)。这是cURL的默认auth模式类型。查看cURL请求的请求标头。你会看到'授权:基本sdfdfkhdfkasdfhsdiu'这是你需要你的请求相同的标题。 'sdfdfkhdfkasdfhsdiu'是'user:pass'的base64编码。 –
-user uname:pass做基本认证。 – Forkmohit