I've been trying to query NCBI blast website using Android and BioJava. I'm using Eclipse with the Android emulator. When I run the code as an Android app I get the following errors:
W/System.err(533): java.io.IOException: An error occured submiting sequence to BLAST server. Cause: content-length promised 2000 bytes, but received 214
When I take the very same code and run it as a regular Java app it works perfectly. Any ideas on what it might be?
It also occured to me while I was trying to make a POST request in Android . If you set Content-Length in headers and the actual content has a different length, it will throw an IOException
in Android (in plain JDK it worked, although it is wrong)
You can reproduce the Exception using the following code:
try {
URL oracle = new URL("http://oasth.gr/tools/lineTimes.php");
HttpURLConnection yc = (HttpURLConnection) oracle.openConnection();
yc.setRequestProperty("User-Agent",
"Mozilla/5.0 (X11; Linux i686; rv:2.0b12) Gecko/20110222 Firefox/4.0b12");
yc.setRequestProperty("Referer",
"http://oasth.gr/tools/lineTimes.php");
yc.setRequestProperty("Accept-Language",
"el-gr,el;q=0.8,en-us;q=0.5,en;q=0.3");
yc.setRequestProperty("Accept-Charset",
"ISO-8859-7,utf-8;q=0.7,*;q=0.7");
// content length should be 29 !!
yc.setRequestProperty("Content-Length", "1000");
// content length is 29 !
String parames = "bline=63&goes=a&lineStops=886";
yc.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(yc.getOutputStream());
wr.write(parames);
wr.flush();
Log.d(TAG, "" + yc.getResponseCode());
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
StringBuilder sbu = new StringBuilder();
while ((inputLine = in.readLine()) != null)
sbu.append(inputLine);
wr.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
Log.e("getLinesArrival Exception", e.getMessage());
}
so if you remove line
yc.setRequestProperty("Content-Length", "1000");
it will work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With