AJAX认证?

Pls see image http://whatcodecraves.com/images/backbonejs-auth-http.png,

I have 2 AJAX requests:

  1. The first one to authenticate, server responded:

    Set-Cookie:JSESSIONID=06AB56403C08AD373BEDE33CBEFBE102; Path=/

  2. Another one to use the session. What should I do with this to send to server to use the same authentication session (a GET request)?

My code:

  1. First AJAX Request:

    $.ajax({
        url : "https://www.hafiz.gov.sa/HRDFWeb/AuthenticateDirectly",
        type : "POST",
        data : {
            "date" : "135854809",
            "json" : JSON.stringify({
                "nin" : "1089194383",
                "password" : "255793"
            })
        },
        success : function(data) {
            console.log(data);
        }
    });
    
  2. Second AJAX Request:

    $.ajax({
        url : 'https://www.hafiz.gov.sa/HRDFWeb/UpdateLastLogin?nin=1089194383&password=255793&date=1374661464&callback=?',
        type : "get",
        dataType: 'jsonp',
        success : function(data) {
            console.log(data);
        },
        error : function(data){
            console.log(data);
        }
    });
    

EDIT:

@w4rumy, Thanks for your answer, but I can't access that code. I'm writing a phonegap android app, this is the code that it uses to connect to server.

HttpPost httpost = new HttpPost("https://www.hafiz.gov.sa/HRDFWeb/AuthenticateDirectly");

List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("date", System.currentTimeMillis() + ""));
nvps.add(new BasicNameValuePair("json", "{\"nin\":\""+idd+"\",\"password\":\""+passs+"\"}"));

try {
    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}

try {
    response = httpclient.execute(httpost);
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
entity = response.getEntity();

Log.v("mytag", "Login form get: " + response.getStatusLine());

if (entity != null) {
    try {
        entity.consumeContent();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Log.v("mytag", "Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();

if (cookies.isEmpty()) {
    Log.v("mytag", "None");
} else {
    for (int i = 0; i < cookies.size(); i++) {
        Log.v("mytag", "- " + cookies.get(i).toString());
    }
}

httpget = new HttpGet("https://www.hafiz.gov.sa/HRDFWeb/UpdateLastLogin?nin=1089194383&password=255793&date=1358448809");
try {
    response = httpclient.execute(httpget);
} catch (ClientProtocolException e1) {
    e1.printStackTrace();
} catch (IOException e1) {
    e1.printStackTrace();
}

try {
    content = response.getEntity().getContent();
} catch (IllegalStateException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐