Can't get Set-Cookie header from http response - java

I am developing a small web content scraper . Part of the code is to send a http request and get the cookie from the response header, so it can be set in the subsequent request.
The code to get the cookies is like this:
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
request.setHeader("Accept-Encoding","gzip,deflate,sdch");
if(cookie!=null)
{
request.setHeader("Cookie", cookie);
}
request.setHeader("Accept-Language","en-US,en;q=0.8,zh-CN;q=0.6");
request.setHeader("Cache-Control", "max-age=0");
request.setHeader("Connetion", "keep-alive");
request.setHeader("Host", "www.booking.com");
request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/32.0.1700.76 Safari/537.36");
try {
HttpResponse response = client.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
System.out.println(statusCode);
//get all headers
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
System.out.println("Key : " + header.getName()
+ " ,Value : " + header.getValue());
}
System.out.println("----------------------------------------------------------");
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The url I used to test is http://www.booking.com/hotel/il/herods-hotels-spa.html#tab-reviews
The result printed is like this:
200
Key : Server ,Value : nginx
Key : Date ,Value : Mon, 03 Feb 2014 05:15:41 GMT
Key : Content-Type ,Value : text/html; charset=UTF-8
Key : Connection ,Value : keep-alive
Key : Cache-Control ,Value : private
Key : Vary ,Value : User-Agent, Accept-Encoding
Key : Set-Cookie ,Value : bkng=11UmFuZG9tSVYkc2RlIyh9YdMHS7ByVcpJ6zdHwCKMHsY37i1DyVPCutMoSY%2F9OR7ixF74JFUj1%2BJ3pF8ntbVX55kLQJvNnfE6Qco2NDwnHPzomws7z40vIxLRgwBTWU9CTbAN3zZqJGksaPN3GqHpSWJ%2BMIKlI5hQN6ZcJnKsU3rR9KXmRVS4plyPQf4gqmsjR131%2BtuuBiULzmDsKzejJZg%2BFgWWUOWS71bCxUGvJbeBBo1HRmUVmigKDEyHylYplnhKkriMof25dYccWyLQoBjIyUL4QZWr58O5D7fKPHDYWSY9y7k%2Bxfk7irIsyKdu%2B0owjpGp2%2BncNdphtqPZqdpeCyky1ReSjWVQ4QuZemceNGmfZGwxm%2BQxu0%2BkBEsJA5zY%2BoqulR8MJIBKZpFqsuvbeDZ9r5UJzl5c%2Fqk7Vw5YU1I%2FQunbw7PHra7IaGp6%2BmHnH2%2BeyiMDhAjWL769ebuwG2DhrgfB6eI0AGZE%2F6T0uA4j7bxA%2FwUdhog6yOu%2FSeTkPl%2FTAiIetVyKLfT1949ggWKfk1kGzmjnowOlZzPbxr1L%2FAifBjInWZ6DreY1Mr2A3%2BfjFYaHJYnS8VpB%2BZappBpGXBUVfHe%2FQ7lbDwNd6TCCzigpsb17LtvFYsb3JiZ%2BQFF82ILNwWFKz6B1xxEEbCRVoq8N%2FcXXPStyGSwApHZz%2Bew6LNI7Hkd2rjB1w3HenUXprZWR3XiWIWYyhMAbkaFbiQV2LThkl2Dkl%2FA%3D; domain=.booking.com; path=/; expires=Sat, 02-Feb-2019 05:15:41 GMT; HTTPOnly
Key : X-Recruiting ,Value : Like HTTP headers? Come write ours: booking.com/jobs
However when I uploaded this small program to my server, and ran it, the result became:
200
Key : Server ,Value : nginx
Key : Date ,Value : Mon, 03 Feb 2014 05:14:14 GMT
Key : Content-Type ,Value : text/html; charset=UTF-8
Key : Connection ,Value : keep-alive
Key : Cache-Control ,Value : private
Key : Vary ,Value : User-Agent, Accept-Encoding
Key : X-Recruiting ,Value : Like HTTP headers? Come write ours: booking.com/jobs
The Set-Cookie header disappeared and my subsequent requests to other content pages within the same site(which are supposed to be loaded by a javascript in the first page I requested) all returned 400 error which I guess is because the cookie missing.
I can't figure out why, and the differences between my pc and the server that I know are:
My pc is running Windows 7 and actually has a Chrome browser, while the server is running Linux and doesn't have any actual browser.
The ip addresses are different.
Other than these, I can't think of any yet.
Any suggestion or advice to solve this problem will be appreciated. Thank you.

set-cookie is a forbidden response header name, you can't read it using browser-side JavaScript
developer.mozilla.org
Browsers block frontend JavaScript code from accessing the Set Cookie header, as required by the Fetch spec, which defines Set-Cookie as a forbidden response-header name that must be filtered out from any response exposed to frontend code.

Related

Apache Jmeter : Post an object not working with ModelAttribute

I am working on stress testing our webapplication written in Spring-MVC.
I would like to send an object Person to the application. I have added a system out to get the email, but whenever I am sending the object, it is null. What am I doing wrong?
Server code :
#RequestMapping(value = "/person/add", method = RequestMethod.POST)
public String addPerson(#ModelAttribute("person") Person person, BindingResult bindingResult) {
try {
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(person);
System.out.println("String is "+json);
}catch (Exception e){
e.printStackTrace();
}
System.out.println("Person add called"+person.getUsername());
person.setUsername(this.stripHTML(person.getUsername()));
int personId = this.personService.addPerson(person);
if (!(personId == 0)) {
Person person1 = this.personService.getPersonById(personId);
Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication authentication = new UsernamePasswordAuthenticationToken(person1, null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
return "redirect:/canvaslisting";
} else {
return "redirect:/";
}
}
Object sent in body data :
{"person":{"id":0,"username":"testemail#gmail.com","firstName":"test","cleanCacheFlag":false,"googleDrive":false,"dropbox":false,"evernoteConsumed":false,"statusChangeTimeStamp":null,"useCalendar":false,"newsletterFlag":false,"tourSteps":null,"profession":null,"notiz":null,"telePhone":null,"lastVisitedBoards":null,"leftGroup":null,"optionalEmail":null,"facebookLink":null,"xingLink":null,"linkedinLink":null,"lastOnlineTimestamp":null,"userRole":null,"homePage":null,"excelImportQuota":0,"toEmail":null,"code":null,"authorities":null,"role":null,"newpassword":null,"token":null,"profilePhotoString":null,"accountNonExpired":true,"credentialsNonExpired":true,"accountNonLocked":true,"active":true,"enabled":false}
}
Output :
Person add callednull
Screenshot :
Sample result
Thread Name: Thread Group 2-5
Sample Start: 2017-06-29 15:17:11 IST
Load time: 6
Connect Time: 0
Latency: 6
Size in bytes: 237
Sent bytes:0
Headers size in bytes: 205
Body size in bytes: 32
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""): text
Response code: 415
Response message: Unsupported Media Type
Response headers:
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1048
Date: Thu, 29 Jun 2017 09:47:11 GMT
Connection: close
HTTPSampleResult fields:
ContentType: text/html;charset=utf-8
DataEncoding: utf-8
Request:
POST http://127.0.0.1:8080/person/add/
POST data:
{"person":{"id":0,"username":"testemail#gmail.com","firstName":"test","cleanCacheFlag":false,"googleDrive":false,"dropbox":false,"evernoteConsumed":false,"statusChangeTimeStamp":null,"useCalendar":false,"newsletterFlag":false,"tourSteps":null,"profession":null,"notiz":null,"telePhone":null,"lastVisitedBoards":null,"leftGroup":null,"optionalEmail":null,"facebookLink":null,"xingLink":null,"linkedinLink":null,"lastOnlineTimestamp":null,"userRole":null,"homePage":null,"excelImportQuota":0,"toEmail":null,"code":null,"authorities":null,"role":null,"newpassword":null,"token":null,"profilePhotoString":null,"accountNonExpired":true,"credentialsNonExpired":true,"accountNonLocked":true,"active":true,"enabled":false}
}
[no cookies]
Request Headers:
Connection: close
Content-Length: 717
Content-Type: application/x-www-form-urlencoded
Change header Content-Type in HTTP Header Manager from:
Content-Type: application/x-www-form-urlencoded
To:
Content-Type: application/json
Shouldn't you just have an #RequestBody annotation on person ?
public String addPerson(#RequestBody Person person);
Well, there is a typo or copy-paste issue in your JMeter request
Also your JMeter configuration might be missing HTTP Header Manager configured to send Content-Type header with the value of application/json

Angular2 - unable to get Set-Cookie from auth. response (jaas, wf)

Iam trying to authenticate from Angular2.1.0 to JAAS form-based j2ee app on WildFly 8.2
let j_username = 'sb2';
let j_password = 'sb222';
let url: string = 'http://127.0.0.1:8888/prototype-rest/j_security_check';
let body = 'j_username=' + j_username + '&j_password=' + j_password;
let headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded'
})
;
//let options = new RequestOptions({headers: headers, withCredentials : true});
let options = new RequestOptions({headers: headers});
this.http.post(url, body, options)
.subscribe(
(res: Response) => {
console.log('res = ' + res);
console.log(res.headers.keys());
var headers = res.headers;
var setCookieHeader = headers.get('Set-Cookie');
console.log('setCookieHeader = ' + setCookieHeader);
},
err => {
console.log('err = ' + err);
}
)
;
response from wildfly
HTTP/1.1 200 OK
Expires: 0
Cache-Control: no-cache, no-store, must-revalidate
X-Powered-By: Undertow/1
Set-Cookie: JSESSIONID=iyD6Yz_Tj7xsIM1zRDHaR2bh.sk-za-04702; path=/prototype-rest
Access-Control-Allow-Headers: accept, authorization, content-type, x-requested-with
Server: WildFly/8
Pragma: no-cache
Access-Control-Expose-Headers: Set-Cookie
Date: Thu, 03 Nov 2016 14:01:41 GMT
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Length: 0
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT
Access-Control-Max-Age: 3600
My problem is that I am not able to read Set-Cookie, if I use withCredentials : true (I am not sure if I should), response fails ... I'd like to add JSESSIONID to request, where I register websocket ...

HttpUrlConnection setting Range in Android is ignored

I'm trying get a 206 response from my server using Android.
Here's the code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
try {
URL url = new URL("http://aviddapp.com/10mb.file");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Range", "bytes=1-2");
urlConnection.connect();
System.out.println("Response Code: " + urlConnection.getResponseCode());
System.out.println("Content-Length: " + urlConnection.getContentLength());
Map<String, List<String>> map = urlConnection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
InputStream inputStream = urlConnection.getInputStream();
long size = 0;
while(inputStream.read() != -1 )
size++;
System.out.println("Downloaded Size: " + size);
}catch(MalformedURLException mue) {
mue.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
}
return null;
}
}.execute();
}
Here's the output:
I/System.out: Respnse Code: 200
I/System.out: Content-Length: -1
I/System.out: Key : null ,Value : [HTTP/1.1 200 OK]
I/System.out: Key : Accept-Ranges ,Value : [bytes]
I/System.out: Key : Cache-Control ,Value : [max-age=604800, public]
I/System.out: Key : Connection ,Value : [Keep-Alive]
I/System.out: Key : Date ,Value : [Tue, 04 Oct 2016 07:45:22 GMT]
I/System.out: Key : ETag ,Value : ["a00000-53e051f279680-gzip"]
I/System.out: Key : Expires ,Value : [Tue, 11 Oct 2016 07:45:22 GMT]
I/System.out: Key : Keep-Alive ,Value : [timeout=5, max=100]
I/System.out: Key : Last-Modified ,Value : [Tue, 04 Oct 2016 07:36:42 GMT]
I/System.out: Key : Server ,Value : [Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4]
I/System.out: Key : Transfer-Encoding ,Value : [chunked]
I/System.out: Key : Vary ,Value : [Accept-Encoding,User-Agent]
I/System.out: Key : X-Android-Received-Millis ,Value : [1475567127403]
I/System.out: Key : X-Android-Response-Source ,Value : [NETWORK 200]
I/System.out: Key : X-Android-Sent-Millis ,Value : [1475567127183]
I/System.out: Downloaded Size: 10485760
Now I'm doing the same thing is pure java.
public static void main(String... args) {
try {
URL url = new URL("http://aviddapp.com/10mb.file");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Range", "bytes=1-2");
urlConnection.connect();
System.out.println("Respnse Code: " + urlConnection.getResponseCode());
System.out.println("Content-Length: " + urlConnection.getContentLength());
Map<String, List<String>> map = urlConnection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
InputStream inputStream = urlConnection.getInputStream();
long size = 0;
while(inputStream.read() != -1 )
size++;
System.out.println("Downloaded Size: " + size);
}catch(MalformedURLException mue) {
mue.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
}
}
Here's the output
Respnse Code: 206
Content-Length: 2
Key : Keep-Alive ,Value : [timeout=5, max=100]
Key : null ,Value : [HTTP/1.1 206 Partial Content]
Key : Server ,Value : [Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4]
Key : Content-Range ,Value : [bytes 1-2/10485760]
Key : Connection ,Value : [Keep-Alive]
Key : Last-Modified ,Value : [Tue, 04 Oct 2016 07:36:42 GMT]
Key : Date ,Value : [Tue, 04 Oct 2016 07:42:17 GMT]
Key : Accept-Ranges ,Value : [bytes]
Key : Cache-Control ,Value : [max-age=604800, public]
Key : ETag ,Value : ["a00000-53e051f279680"]
Key : Vary ,Value : [Accept-Encoding,User-Agent]
Key : Expires ,Value : [Tue, 11 Oct 2016 07:42:17 GMT]
Key : Content-Length ,Value : [2]
Downloaded Size: 2
As you can see I'm getting diffrent response codes in both cases. It seems like Android is not passing Range to the server maybe? What's happening here?
PS: I'm getting a 206 if the file size is 1mb.
I am relatively certain the error is not in the Android code.
It looks like the server might be delivering spurious results.
You can check with a third party tool (such as Postman) to determine the headers that web service is delivering.
My results using Postman. As you can see, it is delivering HTTP 200 (not 206). It is also not wending a capped Content-Length. If the server is yours, perhaps check that it is configured correctly. Also check your code with other servers.
Hi Can u try this piece of code, it seems i am getting HTTP 206 here.
new Thread() {
#Override
public void run() {
try {
URL url = new URL("http://aviddapp.com/10mb.file");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
// urlConnection.setRequestMethod("HEAD");
urlConnection.setRequestProperty("Accept-Encoding", "");
urlConnection.setRequestProperty("Range", "bytes=1-2");
urlConnection.connect();
System.out.println("Response Code: " + urlConnection.getResponseCode());
System.out.println("Content-Length: " + urlConnection.getContentLength());
Map<String, List<String>> map = urlConnection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
InputStream inputStream = urlConnection.getInputStream();
long size = 0;
while (inputStream.read() != -1)
size++;
System.out.println("Downloaded Size: " + size);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
You just have to add this in async task.
Check this result commenting on/off this line.
urlConnection.setRequestProperty("Accept-Encoding", "");
I am not sure if this is related to Content-Length being cleared by android implementation by default. Look at the below snippet from the source code where it says it does gzip compression by default.
https://android.googlesource.com/platform/libcore/+/2e317a02b5a8f9b319488ab9311521e8b4f87a0a/luni/src/main/java/java/net/HttpURLConnection.java
By default, this implementation of HttpURLConnection
requests that servers use gzip compression and it automatically
decompresses the data for callers of getInputStream(). The
Content-Encoding and Content-Length response headers are cleared in
this case.
Can you try disabling the default caching using below code to check if that works?
urlConnection.setRequestProperty("Accept-Encoding", "identity");
PS: Sorry for bad formattings. Using the mobile version of SO.
Have you tried like that:
urlConnection.setRequestProperty("Range", "bytes=1000-");

docx and xlsx files not being downloaded using HttpUrlConnection.getInputStream and FileUtils.copyInputStreamToFile

I'm trying to download a some files via webdav. I have some code which seems to work for all files except for Microsoft files. (e.g., docx, xlsx) By "work", I mean to say that I run the program, and I can find the file in the place that I directed it to be saved.
Here is the code:
String[] folderPaths = path.split("/");
String fileName = folderPaths[folderPaths.length - 1];
String webdavURL = "https://" + WEB_HOST + "/webdav/";
if(path.startsWith("/"))
path = path.replaceFirst("/","");
//System.out.println(webdavURL + folder + fileName);
java.net.URL url = new java.net.URL(webdavURL + path);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
//conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Authorization", "Basic " + new String(new org.apache.commons.codec.binary.Base64().encode("un:pw".getBytes())));
conn.setRequestProperty("User-Agent","curl/7.37.0");
conn.setRequestProperty("Host", WEB_HOST);
conn.setRequestProperty("Accept", "*/*");
//conn.setRequestProperty("Content-Length", String.valueOf(fileContents.length));
//conn.setRequestProperty("Expect", "100-continue");
org.apache.commons.io.FileUtils.copyInputStreamToFile(conn.getInputStream(), file);
//org.apache.commons.io.FileUtils.writeByteArrayToFile(file, org.apache.commons.io.IOUtils.toByteArray(conn.getInputStream()));
Integer returnCode = conn.getResponseCode();
java.io.InputStream errorStream = conn.getErrorStream();
if(errorStream != null)
System.out.println(org.apache.commons.io.IOUtils.toString(conn.getErrorStream()));
java.util.Map<String, java.util.List<String>> map = conn.getHeaderFields();
for (java.util.Map.Entry<String, java.util.List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
conn.disconnect();
return returnCode;
As you can see, I am printing some lines for debugging purposes.
Here are the response headers for a successful download:
Key : null ,Value : [HTTP/1.1 200 OK]
Key : ETag ,Value : ["179614-BA45C8F60456A672E003A875E469D0EB"]
Key : Content-Length ,Value : [845941]
Key : Expires ,Value : [-1]
Key : Last-Modified ,Value : [Fri, 04 Apr 2014 14:13:54 GMT]
Key : Set-Cookie ,Value : [stuff]
Key : X-Powered-By ,Value : [ARR/2.5]
Key : Server ,Value : [Microsoft-IIS/7.5]
Key : Cache-Control ,Value : [private]
Key : Pragma ,Value : [private]
Key : Date ,Value : [Wed, 23 Dec 2015 19:01:39 GMT]
Key : P3P ,Value : [CP="CAO PSA OUR"]
Key : Content-Type ,Value : [image/jpeg]
Key : Accept-Ranges ,Value : [bytes]
And here are the response headers for an xlsx file:
Key : null ,Value : [HTTP/1.1 200 OK]
Key : ETag ,Value : ["205147-70BDF9AF17A2F13756A21AE50EB88DFF"]
Key : Content-Length ,Value : [48002]
Key : Expires ,Value : [-1]
Key : Last-Modified ,Value : [Fri, 29 Aug 2014 20:27:51 GMT]
Key : Set-Cookie ,Value : [stuff]
Key : X-Powered-By ,Value : [ARR/2.5]
Key : Server ,Value : [Microsoft-IIS/7.5]
Key : Cache-Control ,Value : [private]
Key : Pragma ,Value : [private]
Key : Date ,Value : [Wed, 23 Dec 2015 19:01:38 GMT]
Key : P3P ,Value : [CP="CAO PSA OUR"]
Key : Content-Type ,Value : [application/x-www-form-urlencoded]
Key : Accept-Ranges ,Value : [bytes]
I really have no idea what might be going wrong here. I get a 200 response from the server, and there are no reported errors or exceptions.
The only thing that stands out to me is that, when trying to download an xlsx file, the Content-Type is application/x-www-form-urlencoded while with anything else, the content-type actually lists the type of file that it is. I would not have thought that that would make a difference.
Any ideas at all would be greatly appreciated!
it was conn.setDoInput and conn.setDoOutput. Commenting those out made it work. I didn't really know what they did; I just copied this code from a previous project.

HttpUrlConnection.getContentLength() returns -1 but the header field exists

I'm experiencing a strange behavior of my Java application which download files from a Web server. I download APK files or bash scripts. Both are served the same way by the server but when I download a bash script, the getContentLength() method returns the right content length and when I download an APK file, the method returns -1...
Here is the PHP function I use to serve the files :
function send_file($file) {
header('Content-Type: application/force-download; name="' . basename($file) . '"');
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
readfile($file);
exit();
}
And the Java code to download the files :
URL requestUrl = new URL("http://download.myesmart.net/api.php?id=" + Tablet.ID + "&type=" + type);
// Start the connection to the server
if ((connection = (HttpURLConnection) requestUrl.openConnection()) == null) {
Log.d("TAG", "Impossible to contact the server.");
return null;
}
connection.connect();
// Check the HTTP code
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
Log.d("TAG", "Bad server response : " + connection.getResponseMessage());
return null;
}
// Return -1 sometimes...
Log.d("TAG", "Content-Length : " + connection.getContentLength());
If I check the HTTP header fields this Web tool : http://www.webconfs.com/http-header-check.php, I get the same response type but the first works and the second doesn't.
HTTP/1.1 200 OK =>
Set-Cookie => mailplan=R243416773; path=/; expires=Thu, 13-Nov-2014 09:19:48 GMT
Content-Type => application/force-download; name="configure-keyboard.sh"
Server => Apache
Content-Transfer-Encoding => binary
Content-Disposition => attachment; filename="configure-keyboard.sh"
Expires => 0
Cache-Control => no-cache, must-revalidate
Pragma => no-cache
Vary => Accept-Encoding
Accept-Ranges => bytes
Date => Thu, 13 Nov 2014 08:19:39 GMT
Connection => close
X-Geo => varn16.rbx5
X-Geo-Port => 1015
X-Cacheable => Not cacheable: no-cache
Content-Length => 1118
HTTP/1.1 200 OK =>
Set-Cookie => mailplan=R1918955109; path=/; expires=Thu, 13-Nov-2014 08:59:12 GMT
Content-Type => application/force-download; name="InfoConfort_20141102_ec_v1dev.apk"
Server => Apache
Content-Transfer-Encoding => binary
Content-Disposition => attachment; filename="InfoConfort_20141102_ec_v1dev.apk"
Expires => 0
Cache-Control => no-cache, must-revalidate
Pragma => no-cache
Vary => Accept-Encoding
Accept-Ranges => bytes
Date => Thu, 13 Nov 2014 07:53:43 GMT
Connection => close
X-Geo => varn16.rbx5
X-Geo-Port => 1015
X-Cacheable => Not cacheable: no-cache
Content-Length => 5149910
Any idea ???
According to JavaDocs getContentLength method returns -1, if content length is not known yet.
Would you mind to try this:
URL requestUrl = new URL("http://download.myesmart.net/api.php?id=" + Tablet.ID + "&type=" + type);
//Start the connection to the server
if ((connection = (HttpURLConnection) requestUrl.openConnection()) == null) {
Log.d("TAG", "Impossible to contact the server.");
return null;
}
connection.setRequestProperty("Accept-Encoding", "identity")
Log.d("TAG", "Content-Length : " + connection.getContentLength());
edited.

Categories