我可以在命令行上使用以下命令来使用REST服务。
curl -v --user uname:pass -H" Accept:application / xml" http://xyz.abc.def
同样的AJAX是什么?如何在ajax调用中提供用户名:密码?我当前没有uname的函数:pwd是:
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);
}
});
}
&#13;
PS:服务由Spring Security保护
答案 0 :(得分:3)
让我们分解curl命令:
curl -v --user uname:pass -H&#34; Accept:application / xml&#34; http://xyz.abc.def
-v用于详细,在ajax中不需要
- user是纯文本用户身份验证,但它是作为基本身份验证发送的
-H&#34;接受:application / xml&#34;是添加标题&#34;接受:application / xml
在jQuery ajax中复制这个我们需要做一些事情:
// this function takes a username and password
function make_base_auth(user, password) {
var tok = user + ':' + pass;
// Base64 encoding is what is used by basic auth let's encode our username:password
var hash = Base64.encode(tok);
// Let's return the auth header
return "Basic " + hash;
}
// let's get the data
function getData() {
var name, code;
var serviceURL = "http://xyz.abc.def";
// getting the auth header value
var basicAuth = make_base_auth(uname, pass);
$.support.cors = true;
$.ajax({
// using http get as the command type
type: "GET",
// accepting xml as the return type
dataType: "xml",
crossDomain: true,
url: serviceURL,
// setting the basic auth header
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", basicAuth);
},
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);
}
});
}
&#13;
请注意[MPO]: 如果服务接受JSONP,我会建议使用而不是CORS,但是要么会给出相同的最终结果。< / em>的
答案 1 :(得分:1)
嗨,如果你想覆盖htpasswd安全性,我认为你只需要写下你的网址:
SELECT
*
INTO #temp
FROM source T010T
LEFT JOIN destination P510T
ON WH_CD = T010T.WH_CD
AND POS_NO = T010T.POS_NO
AND SLIP_NO = T010T.TRAN_NO
AND OPE_DATE = T010T.SL_REC_DATE
WHERE P510T.WH_CD IS NULL