Checking for Server Response Code 200 in C -


Then I have this script which sends barcodes to a server (which should answer 200 codes when receiving the barcode). What I want to know is how can I see it in my script? For example, if (server rpspoint == 200)
printf (your barcode has been transmitted)

my bad english and mine Sry for very bad knowledge

  # include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; Int main (int argc, char * argv []) {while (1) {char buf [256], syscmd [512]; Int i; / * Get the next barcode * / printf ("Waiting for the bar code [q = left]:"); Break if (fgets (buf, 255, stdin) ==); / * For clear CR / LF closed string * / i (i = 0; buf [i]! = '\ 0' and buff [i]! = '\ R' and buffer [i]! = ' \ N '; i ++); Buf [i] = '\ 0'; / * Q = Skip * / if break (Strcmp (buf, "q")); / * Create curl command in command * / sprint (syscmd, "curl \" http: //www.xyz.com/test/order/complete? Barcode =% s \ "", buf); Execute / * - It will wait to complete the command before continuing. * / System (syscmd); } Return (0); }   

I will look in popen, because curl stdout will be default to print data (If not, look at the man curls), Popayan will let you read that data.

The HTTP header () indicates that where that code is exactly the same, besides, I suggest to make sure that the data do not overflow syscmd.

  char * base = "curl \" http://www.xyz.com/test/order/complete?barcode= \ ""; If (Stellan (base) + Stellen (buff)> 511) {fprintf (stderr, "error! Buffer overflow! \ N"); Return 1; } Else {sprintf (syscmd, "curl" http: //www.xyz.com/test/order/complete? Barcode =% s \ "", buf); FILE * p = popen (syscmd, "r"); Edit: Code is very simple to check  
  
  // Assume that you use code above code are doing; Fscanf (P, "HTTP / 1.1% D", and code); // if either HTTP / 1.1 or HTTP / 1.0 is based on your server (code == 200) {printf ("yupp, all good :) \ n"); } Else {printf ("The server did not do so well with that request: (\ n");}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -