weixin_33716154 2013-07-26 07:58 采纳率: 0%
浏览 33

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();
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记