Movatterモバイル変換


[0]ホーム

URL:


everything curl

    Get URL parts

    TheCURLU handle stores the individual parts of a URL and the applicationcan extract those pieces individually from the handle at any time. If they areset.

    The second argument tocurl_url_get() specifies which part you wantextracted. They are all extracted as null-terminatedchar * data, so youpass a pointer to such a variable.

    char *host;rc = curl_url_get(h, CURLUPART_HOST, &host, 0);char *scheme;rc = curl_url_get(h, CURLUPART_SCHEME, &scheme, 0);char *user;rc = curl_url_get(h, CURLUPART_USER, &user, 0);char *password;rc = curl_url_get(h, CURLUPART_PASSWORD, &password, 0);char *port;rc = curl_url_get(h, CURLUPART_PORT, &port, 0);char *path;rc = curl_url_get(h, CURLUPART_PATH, &path, 0);char *query;rc = curl_url_get(h, CURLUPART_QUERY, &query, 0);char *fragment;rc = curl_url_get(h, CURLUPART_FRAGMENT, &fragment, 0);char *zoneid;rc = curl_url_get(h, CURLUPART_ZONEID, &zoneid, 0);

    Remember to free the returned string withcurl_free when you are done withit!

    Extracted parts are not URL decoded unless the user asks for it with theCURLU_URLDECODE flag.

    URL parts

    The different parts are named from their roles in the URL. Imagine a URL thatlooks like this:

    http://joe:7Hbz@example.com:8080/images?id=5445#footer

    When this URL is parsed by curl, it stores the different components like this:

    textpart
    httpCURLUPART_SCHEME
    joeCURLUPART_USER
    7HbzCURLUPART_PASSWORD
    example.comCURLUPART_HOST
    8080CURLUPART_PORT
    /imagesCURLUPART_PATH
    id=5445CURLUPART_QUERY
    footerCURLUPART_FRAGMENT

    Zone ID

    The one thing that might stick out a little is the Zone id. It is an extraqualifier that can be used for IPv6 numerical addresses, and only for suchaddresses. It is used like this, where it is set toeth0:

    http://[2a04:4e42:e00::347%25eth0]/

    For this URL, curl extracts:

    textpart
    httpCURLUPART_SCHEME
    2a04:4e42:e00::347CURLUPART_HOST
    eth0CURLUPART_ZONEID
    /CURLUPART_PATH

    Asking for any other component returns non-zero as they are missing.


    [8]ページ先頭

    ©2009-2025 Movatter.jp