저는 프로젝트에서 일하고 있으며 지금까지 해결할 수 없었던 문제를 보았습니다.HTTP 헤더 토큰 가져 오기
프로젝트는 jquery 모바일 프레임 워크를 사용하여 빌드 된 모바일 웹 응용 프로그램입니다. 웹 응용 프로그램은 wcf 서비스에서 json을 가져 와서 jquery mobile UI 효과를 사용하여 렌더링 할 수 있습니다. 우리는 나의 문제가있는 토큰 기반 보안을 구현하는 단계에 도달했습니다. 지금은 다른 모든 Ajax 요청에 사용할 사용자 지정 HTTP 헤더를 추가하려고합니다.
function login_service()
{
//$.mobile.pageLoading();
var stringUsername = $('#txtUsername').val();
var stringPassword = $('#txtPassword').val();
$('#loginMessage').empty(); // Empty message div
$.ajax(
{
url: "urlstring"+stringUsername+"/"+stringPassword, // This URL uses https
dataType: "jsonp",
type: 'GET',
beforeSend: setHeader,
success: function(loginResult)
{
$('#loginMessage').html('<a>'+ loginResult.tkt + '</a>');
tkn = loginResult.tkt; // Json token
if(tkn == null)
{
$('#loginMessage').append("invalid login:" + ' ' + '<br>' + "token:" + ' ' + tkn);
$.mobile.pageLoading(true);
}
else
{
$.mobile.changePage('#search'); // Change page to search screen
}
},
error: function(status)
{
alert(status);
$.mobile.pageLoading(true); // End loading animation
}
})
}
function setHeader(xhr)
{
xhr.setRequestHeader('Authorization', tkn);
alert("header set");
}
function doSearch_webservice(){ // Start of function webservice
$.ajax({ // Start of ajax call
url: "urlstring"+$('#jsonSearch').val(), // If URL string is http, custom header will
// be displayed in fiddler/firebug. IF HTTPS custom header won't work.
dataType: 'jsonp',
type: 'GET',
timeout: '20000',
beforeSend: setHeader,
success: function(json_results)
{// Start of success function
if(json_results.keys == null)
{
$('#errMessage').html('<p class="error"><strong>'+ "Status:"
+ "No record found" + "<br>Please try again" +'</strong> </p>');
$.mobile.pageLoading(true);
}
else
{
$('#jsonResponse ul').remove();
// jquery mobile type i.e. data-inset
$('#jsonResponse').append('<ul class="listItems" data-role="listview" data-inset="true"></ul>');
var listItems = $('#jsonResponse').find('ul');
$.each(json_results.keys, function(key) { // Start of each loop
html=
'<a href="#" data-transition="slide" data-position="inline"OnClick="passQryStrg(\''+json_results.keys[key].id+'\' , \''+json_results.keys[key].cat+'\');">'+'<br>'+' '+'<font class="big-text"><b>'+' '+json_results.keys[key].lbl[0]+' '+'</font></b>'+' '+'<font class="small-text">'+' '+'<br>'+' '+json_results.keys[key].lbl[1]+' '+'</font>'+'</a>'
listItems.append('<li>'+html+'</li>');
}); // End of each loop
$('#info jsonResponse ul').listview();
$.mobile.pageLoading(true);
$.mobile.changePage("#info", { transition: "slide"});
$("#info").page("destroy").page();
}
// Destroy the page - next function call won't break css
}, // End of success function
error: function(jqXHR, textStatus, errorThrown)
{
$('#errMessage').html('<p class="error"><strong>'+ "Status:" + textStatus + "<br>Please try again" +'</strong> </p>');
$.mobile.pageLoading(true);
}
}); // End of ajax call
}; // Emd of webservice function
요약 : do_search 아약스 요청이 HTTP URL을 사용하는 경우 나는 사용자 정의 헤더를 추가 할 수 있습니다. 그러나 우리의 wcf 서비스가 사용하는 https로 URL을 변경해야합니다. 이 변경을하면 사용자 정의 헤더가 작동을 멈 춥니 다. 죄송합니다. 설명이 명확하지 않은 경우 최선을 다해 답변 해 드리겠습니다.
감사
내 jquery ajax 요청에 https url을 사용하면 누구든지 내 http 헤더가 작동하지 않는 것을 알 수 있습니까? –