html - getting url param value encoded in some format -


I have written the code below to get the value of the URL parameter.

  char * param (char * attribute_name) {char * query_str = getenv ("QUERY_STRING"); UrlDecode (query_str); Printf ("qstr =% s 
query_str); Int i; Char * param_value; Char * temp = malloc (strlen (attribute_name) + 3); Four * x; Strcpy (temp, "?"); Dome (temp, att_t_name); Dome (temporary, "="); X = Strust (query_str, temp); Att_t_name = strdup (attribute_name); If (x == faucet) {free (temporary); Temp = malloc (strlen (attribute_name) + 3); Strcpy (temp, "& amp;"); Dome (temp, att_t_name); Dome (temporary, "="); X = Strust (query_str, temp); } If (x! = Null) {param_value = malloc (strlen (x) - strlen (temp) + 1); Int s = strlen (x) - strlen (temp); Int t = strlen (x) - s; Strncpy (param_value, and x [t], 1); (I = strlen (temp) + 1; i & lt; = strlen (x); i ++) {if (x [i]! = '& Amp;' ') {strncat (param_value, and x [i] 1); } And {break} }}} Free (temporary); Return param_value; } Int urlDecode (char * str) {unsigned int i; Four TMP [Bufsys]; Char * ptr = tmp; Memmets (TMP, 0, Saiff (TMP)); (I = 0; i & lt; strlen (str); i ++) {if (str [i]! = '%') {* Ptr ++ = str [i]; to continue; } If (ISDiGit (str [I + 1]) || ISDiGit (str (I + 2)) {* ptr ++ = str [i]; to continue; } * Ptr ++ = ((str [i + 1] - '0') <4> 4) | (Str [i + 2] - '0'); I + = 2; } * Ptr = '\ 0'; Strcpy (str, tmp); Return 0; }

and below is my main function:

  int main () {printf ("content-type: text / html \ n \ r \ n \ R "); Printf ("& lt ;; Doctype html & gt;"); Printf ("& lt; html>"); Printf ("& lt; meta charset = \" UTF-8 \ "& gt; & gt; Meta http-equiv = \" content-type \ "content = \" text / html; charset = UTF-8 \ "& Gt;); printf ("k & lt; body & gt;"); four letters [] = "u"; char * value = param; attribute (value); // free (value); printf (" "); return 0;}  

and after killing the URL below I got the output received on the browser

qstr = u = 1212 & sa = 232 3 and sdd = jdwjdz

l12

please correct me Where is the mistake I am? Thanks! / P>

Here's a quick task that I have to do with strstr Strchr and memchr . This is what you are looking for.

  #include & lt; string.h> gt; include & lt; stdio.h & gt; #include & lt; stdlib.h & gt; Char * find_param (char) * Param, char * query_str) {char * p, * p2, * value; P = strchr (query_str, '?'); If (! P) return tap; Do {p = strstr (p + 1, ultimate); } While (P & P [Stellen (ultimate)] = '='); If (! P) return tap; P + = (1 + strlen (ultimate)); P2 = membrar (p, 'end', strollon (p)); If (! P2) P2 = P + Stellen (P); Value = Molkok (P2 - P + 1); Strapepie (value, p); Value [p2 - p] = '\ 0'; return value; } Int main () {printf ("% s", find_param ("u", "http://example.com/cgi-bin/cgi_param?u=1212&ass=232%203&sdd=jdwjdjw")); Return 0; }  

Print:

  1212  

Also with sa and SDD .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -