I sign my http request with a custom authorization header:
String key="client="+USER+",hash="+sha1(STR, API_KEY)+",timestamp="+t.toString(); If anybody is interested in the sha1 method: http://pastebin.com/HRFXQ4Bk The key string is used as header:
URL url = new URL(sb.toString()); HttpURLConnection conn = null; conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", key); conn.setRequestMethod("GET"); InputStreamReader in = new InputStreamReader(conn.getInputStream()); When I try to get the response I get following error:
10-28 18:25:40.111: E/error(6855): java.io.EOFException 10-28 18:25:40.111: E/error(6855): at libcore.io.Streams.readAsciiLine(Streams.java:203) 10-28 18:25:40.111: E/error(6855): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579) 10-28 18:25:40.111: E/error(6855): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827) 10-28 18:25:40.111: E/error(6855): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283) 10-28 18:25:40.111: E/error(6855): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
On my server no access was logged by this request. However when I remove the auth header a connection to my server is established according to the server log.
So how does the auth header influence the request? Why is there no connection when using header?
BTW a header like
conn.setRequestProperty("Authorization", "FOOBAR"); works, however is refused because the authorization header does not match the requirements:
10-29 08:12:07.235: E/error(23663): java.net.ConnectException: failed to connect to api.myserver.net (port 1337): connect failed: ECONNREFUSED (Connection refused) 10-29 08:12:07.235: E/error(23663): at libcore.io.IoBridge.connect(IoBridge.java:114) 10-29 08:12:07.235: E/error(23663): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) 10-29 08:12:07.235: E/error(23663): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
My webservice requires the header to have following format
match(/client=([^,]*),hash=([^,]*),timestamp=([^,]*)/); So this exception is different from the initial exception. When I remove the header and disable authorization on my webservice the connection works as expected. So the problem seems to be with the custom authorization header. Any ideas?
java.net.Authenticator,not rolling your own.