Archived

This topic is now archived and is closed to further replies.

[java] Acsii Chars and http headers

This topic is 5751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a stupidly simple question... I was working on an app that basically uses sockets to call a webpage from a web-server, so I can tunnel through a firewall. In order to do so I need to hand roll my own HTTP headers to make sure they are being handled correctly by the proxy. Apparently older Netscape browsers cannot handle proxies with the URLConnection method. I''ve done this a million times in visual basic(don''t laugh), so I know the process for doing this. But the server doesn''t respond. I am assuming this is because my header request is not formatted correctly. After double checking the header message I am sending the only thing I can find that might be wrong is the carriage return and line feed characters. I wasn''t able to find an asc() function like there is in just about any other language, so I was wondering if I am doing this correctly. Here is my code for generating those characters, and how I make the header.
  
private static String CRLF;
private static byte byCRLF[];
	
static{
	byCRLF = new byte[2];
	byCRLF[0] = 10;
	byCRLF[1] = 13;
		
	CRLF = new String(byCRLF);
}


private String createHeader(String sFile){
	String strTmp = new String();
	
	//Create the HTTP header for the HTTP request

	strTmp = "GET " + sFile + " HTTP/1.1" + CRLF;
	strTmp = strTmp + "Host: " + this.hostIp + CRLF;
	//Use 2 carriage returns and linefeeds to end the request

	strTmp = strTmp + "Connection: close" + CRLF + CRLF;
	
	return strTmp;
}
  
Is this the correct way to generate those characters. BTW webservers don''t understand the /n convention so please don''t tell me to use that. Any other suggestions would be greatly appreciated. -Just when you think things are starting to look up, life grabs you by the jaws makes you open up wide and sh*ts down your throat.

Share this post


Link to post
Share on other sites
Hehe oops, Looks like the \n does work. Sorry about that. I was using /n in my code that I was testing.

-Just when you think things are starting to look up, life grabs you by the jaws makes you open up wide and sh*ts down your throat.

Share this post


Link to post
Share on other sites