I'm using ServerSocket to listen to a certain port on an Android app in order to get a response from a server. When the server sends the http response I receive it as a socket and then I use the Input Stream to get the data.
Any way, everything works great and I get the Http Response but as a string (because I'm reading the Input Stream and then decode it to string):
GET /?code={Some code} HTTP/1.1
Host: localhost:9004
Connection: keep-alive
.
.
.
{More headers}
What I need is to parse the code (first row) but I don't want to process the string by my self. I'm sure there's a easier way.
ServerSocket serverSocket = new ServerSocket(9004);
serverSocket.setReuseAddress(true);
serverSocket.setReceiveBufferSize(1500);
if(!serverSocket.isBound()) {
SocketAddress localAddress = new InetSocketAddress(9004);
serverSocket.bind(localAddress);
}
Socket socket = serverSocket.accept();
InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
int count = is.read(buffer);
String response = new String(buffer, "UTF-8");
// What should I do here??
serverSocket.close();
Thanks a lot!