Best ways of parsing a URL using C?

后端 未结 10 1798
死守一世寂寞
死守一世寂寞 2020-11-27 15:36

I have a URL like this:

http://192.168.0.1:8080/servlet/rece

I want to parse the URL to get the values:

IP: 192.168.0.1
Por         


        
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 15:53

    Libcurl now has curl_url_get() function that can extract host, path, etc.

    Example code: https://curl.haxx.se/libcurl/c/parseurl.html

    /* extract host name from the parsed URL */ 
    uc = curl_url_get(h, CURLUPART_HOST, &host, 0);
    if(!uc) {
      printf("Host name: %s\n", host);
      curl_free(host);
    }
    

提交回复
热议问题