This is what I have so far. I've been trying different snippets of code found from around the Internet, but none of them appear to be doing what I need.
URL url = new URL(urlstr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "text/plain");
connection.setRequestProperty("charset", "utf-8");
connection.connect();
connection.disconnect();
The Server part of my program just receives an empty request. There are 0 bytes to read from the headers. But when I call the same address from my Firefox browser, then about 400 bytes are available to read.
The crucial part of the header is the first line, which looks like
GET [URL]http://localhost/program/function?param1=a¶m2=b[/URL] HTTP/1.0\r\n.This from where I get and parse the parameters. But you could imagine that if it doesn't exist the program fails to work.
Ideas?
Edit: Funny, how often solutions appear right after you've asked for help, even if you struggled for hours or days with the problem. It appears that not every inputstream returns the correct number of bytes available with the available() method. Thus the headers were there all along, it just returned the wrong number of bytes available to read in the server side.


Sign In
Create Account


Back to top









