Skip to content

Instantly share code, notes, and snippets.

@svkrclg
Last active December 19, 2021 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svkrclg/36183b2dcbd1f60b599b726ead739f37 to your computer and use it in GitHub Desktop.
Save svkrclg/36183b2dcbd1f60b599b726ead739f37 to your computer and use it in GitHub Desktop.
procees POST packet
public String[] processData(String request) {
String lines[] = request.split("\r\n");
int cl = -1;
for(String line : lines) {
System.out.println(line);
if(line.contains("Content-Length")) {
String x = line.substring(16);
cl = Integer.parseInt(x);
break;
}
}
String body = request.split("\r\n\r\n")[1]; // head and body are seperated through \r\n\r\n. Ref packet format.
System.out.println("Got body" + body);
if(body.length() == cl) {
return new String[] {"true", body};
}
return new String[] {"false", ""};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment