I am seeing this in Apache Logs. Basically the request is going from Android Emulator using HTTPUrlConnection
. Here is my code.
URL url = new URL(strUrl);
Log.d(params[0],"UR");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Basic " + Base64.encodeToString(toencode, Base64.DEFAULT));
conn.setRequestProperty("Host", "www.domain.com");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestMethod("GET");
conn.setConnectTimeout (30000) ;
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
String data = conn.getInputStream().toString();
return data;
I am sending the user-agent header to make sure the server is not filtering non-recognizable user agents. I captured the traffic using Wireshark. The request seems to be okay. Not sure what else to look for. Spending hours on this without luck.
GET Authenticate/ HTTP/1.1\r\n
Host: www.domain.com\r\n
User-Agent: Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)\r\n
Accept-Charset: UTF-8\r\n
Connection: Keep-Alive\r\n
Accept-Encoding: gzip\r\n
\r\n
Response from Server:
Request Version: HTTP/1.1
Status Code: 400
Response Phrase: Bad Request
<h1>Bad Request</h1>\n
<p>Your browser sent a request that this server could not understand.<br />\n
and in the apache logs:
client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23)
At this point I feel like I need to go back to HttpClient and try it. I thought I should use HttpUrlConnection
because google recommends it. But I am having no luck with HttpURLConnection
.
Anyone has any idea?