httpurlconnection

HttpURLConnection: What's the deal with having to read the whole response?

核能气质少年 提交于 2019-12-13 17:40:14
问题 My current problem is very similar to this one. I have a downloadFile(URL) function that creates a new HttpURLConnection, opens it, reads it, returns the results. When I call this function on the same URL multiple times, the second time around it almost always returns a response code of -1 (But throws no exception!!!). The top answer in that question is very helpful, but there are a few things I'm trying to understand. So, if setting http.keepAlive to false solves the problem, it indicates

MultipartEntityBuilder to send data from Android httpurlconnection

与世无争的帅哥 提交于 2019-12-13 14:20:17
问题 i am trying to change HTTPClient deprecated code but i get error on setEntity because its dapricated and i dont know how to paas MultipartEntityBuilder by new httpConnectionUrl. my old deprecated code snippt try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(imagePostUrl); for (String fileName : fileNameArrayList) { File file = new File(fileName); // 1st int quality = GeneralUtil.getQualityOfImage(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(); if

Image writing over URLConnection

随声附和 提交于 2019-12-13 14:15:09
问题 I am trying to write an image over an HttpURLConnection. I know how to write text but I am having real problems trying to write an image I have succeeded in writing to the local HD using ImageIO: But I am trying to write Image by ImageIO on url and failed URL url = new URL(uploadURL); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setUseCaches(false); connection

How to post multi-part/form images with string parameter in android

浪尽此生 提交于 2019-12-13 07:36:36
问题 I have an API which has a payload body of type String. But has both json and image (multiparty/form) as part of the payload body. Something like this: json={jsonbody} image=@images/testing.png This is what i am doing currently public static String uploadImageQuery(Context context, String urlString, String method, JSONObject jsonObject, Bitmap largeImageBitmap, Dialog dialog) throws IOException { String responseString = null; HttpURLConnection conn = null; URL url = new URL(urlString); conn =

Click on input type “button” calling asp method programmatically from java

南笙酒味 提交于 2019-12-13 07:32:00
问题 I am doing project to scrape data from a website. The html page has an option to save data in excel file. The input element looks as the following: <input type="button" id="SaveXLS" class="func_button excel_sel" title="some title" onclick="doSave2XLS(1886);"> Below are headers to submit the form and after I manually click on a button to save the data in the file. I want to save files programmatically based on form submitted and data produced: http://www.somewebsite.com/iss/modules/dosearch

how to post a form with some cookie

不问归期 提交于 2019-12-13 06:02:02
问题 i have posted a question for htmlunit in this link: how to use htmlunit with my android project mainly i have a link, which i have get after login (i have login through web view) this link give me a simple page. in that page there is a textarea and a submit button. and there are some javascript too (i think these javascript run, when i press the submit button). i can do it through webview, but for some reason i don't want to use webview. whene i press submit button, it deliver the value of

In ICs, can`t get cookie

╄→尐↘猪︶ㄣ 提交于 2019-12-13 05:57:36
问题 cookie return always null... In android 2.x this works well, but 4.0.4 ICS not works ConnectivityManager manager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); CookieManager cookie = CookieManager.getInstance(); if(cookie.getCookie(mContext.getString(R.string.host_url))!=null){ conn.setRequestProperty("Cookie", cookie.getCookie(mContext.getString(R.string.host_url))); Log.d("tag", "cookie get " + cookie.getCookie(mContext.getString(R.string.host_url))); } in

How to execute javascript on a webpage using java

醉酒当歌 提交于 2019-12-13 04:43:18
问题 I am establishing a HttpUrlConnection with a webpage . Now I have javascript snippet that I want to execute on this webpage . How can I do this ? 回答1: You could try : private static ScriptEngineManager mgr = null; private static ScriptEngine engine = null; mgr = new ScriptEngineManager(); engine = mgr.getEngineByName("JavaScript"); Object eval = engine.eval(s); // s is javascript code 回答2: Since Javascript needs some kind of Virtual Machine to run in - usually provided by browsers or

java create HTTP persistent connection

萝らか妹 提交于 2019-12-13 03:56:14
问题 I am trying to write a java program that will automatically download and name some of my favorite web comics. Since I will be requesting multiple objects from the same domain, I wanted to have a persistent http connection that I could keep open until all the comics have been downloaded. Below is my work-in-progress. How do I make another request from the same domain but different path without opening a new http connection? import java.io.BufferedReader; import java.io.IOException; import java

IOException with URLConnection and getInputStream

孤街浪徒 提交于 2019-12-13 00:33:27
问题 I'm trying to get data from a website with an android application. Here is my code : URL url = new URL("http://www.google.com/ig/api?weather=Schriesheim,Germany"); URLConnection uCon = url.openConnection(); iStream = uCon.getInputStream(); The method getInputStream() returns me an IOException, I already tried lots of things find on Internet, but nothing is working. By the way, I tried this code in a Java application and it worked so I assume this the problem is in my Android settings. I