www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to request a url with parameters

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    how to request a url with parameters

    i m trying to implement captcha in my site.i m using recaptcha.

    To check the captcha

    i need to request url like:
    http://www.google.com/recaptcha/api/verify?privatekey="key"&remoteip="ip"&challenge="chal"&response="res"

    and then i need to check response from this url if it is true or false

    i dont know how to post request response from url

    help plz

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    document.url will get you the whole URL, including the parameters. Then you just have to split() that, first by "/", then by "?". Here is something I threw together that should help you understand.

    Code:
    function getURLandNVP() {
        var thisURL = document.URL;
        var arrayURL = new Array();
            arrayURL = thisURL.split("/");
        var arrayLen = arrayURL.length;
        var thisDelim = "/";
        var thisPath = "";
        var thisNVP = "";
        var qs = false;
        var nvp, thisPart, pre, sp;
        for(i=3; i<arrayLen; i++) {
            thisPart = arrayURL[i];
            thisPartLen = thisPart.length;
            nvp = thisPart.indexOf("?");
            sp = thisPart.indexOf(".");
            if((nvp == -1) && (!qs)) { // If NO URL parameters, add to path
                thisPath += thisDelim + thisPart;
                }
            else if((nvp > -1) && (!qs)) { // If URL parameters, get path and separate from URL parameters
                pre = thisPart.substring(0,nvp);
                thisPath += thisDelim + pre;
                thisNVP = thisPart.substring(nvp+1,thisPartLen);
                thisNVP = thisNVP.replace("&","\n","all");
                }
            else if((sp > -1) && (!qs)) { // If using slash delimiter after document name
                qs = true;
                thisPath += thisDelim + thisPart;
                }
            else if(qs) {
                thisNVP += "\n" + thisPart;
                }
            }
        var thisAlert = thisPath; if(thisNVP.length != 0) { thisAlert += "\nwith NVP of\n" + thisNVP; }
        alert(thisAlert);
        }
    Put onload="getURLandNVP();" into the body tag, then load the page; it will give you the URL. If you then put some parameters behind the URL (ie "?a=1&b=2&c=I%20like%20NVP") and load the page, you will see the URL parameters included.

    ^_^

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    actually i dont have to create page which reads parameter from url.....

    its alredy created by google
    for example

    copy and paste this in address bar

    http://www.google.com/recaptcha/api/verify?privatekey="key"&remoteip="ip"&challenge="chal"&response="res"

    then a page will be displayed with

    false
    'Input error: challenge: Error parsing captcha challenge value\nprivatekey: Format of site key was invalid\n'


    i need to read the first statement if it is true or false

  4. #4
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    I understood your question. I suggested creating a page and including my code so you can have a better understanding of how to read URL variables; then you can take that understanding and apply it to what Google is returning in their URL parameters.

    ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles