urlconnection

Can't get server certificate from site

谁说我不能喝 提交于 2019-12-10 11:15:37
问题 I can't get the certificate from my website (neither other website). I tried some solutions with HttpsURLConnection and the method getServerCertificates but nothing solves the problem. URL httpsURL = new URL("https://www.google.com.br/"); HttpsURLConnection connection = (HttpsURLConnection)httpsURL.openConnection(); Certificate[] certs = connection.getServerCertificates(); I get an exception saying that "getServerCertificates cannot be resolved." I don't think its necessary to use keystore,

Java HttpURLConnection: Content Length computation

你离开我真会死。 提交于 2019-12-08 17:38:35
问题 I'm currently developing a library for the bitbucket issues RESTful API. I made good progress and now I'm going to tackle the section Updating an Issue which demands an HTTP PUT Request. Now I'm stuck because of the HTTP Error Code 411 Length Required . After a bit of googling, I found the following code example: // CORRECT: get a UTF-8 encoded byte array from the response // String and set the content-length to the length of the // resulting byte array. String response = [insert XML with UTF

Read-Only error when saving image from URL in Android

假装没事ソ 提交于 2019-12-08 09:37:31
问题 I am trying to save an image from a web URL in an android application however when I run it, the log cat throws an exception saying its "read only". I don't know whats going on. Here is my downloader class: public class ImageDownload { public static void downloader(String imageURL, String fileName) { try { URL url = new URL("http://www.exampleurl.com/" + imageURL); File file = new File(fileName); URLConnection con = url.openConnection(); InputStream is = con.getInputStream();

setImageURI / setimagebitmap to fetch image from net and display in image view

倾然丶 夕夏残阳落幕 提交于 2019-12-08 01:36:32
问题 I want to fetch image from net from some URL and show it in my ImageView. following is the code i am using :- Bitmap bm = null; try { URL aURL = new URL("stringURL"); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); }catch (Exception e) { // TODO: handle exception } iv.setImageBitmap(bm); but i can not get the image 回答1: I

Setting “User-Agent” parameters for URLConnection for querying Google from a Java application

帅比萌擦擦* 提交于 2019-12-07 17:49:01
问题 I am trying to get the results back from a Google query, in Java as follows: String urlquery = "https://www.google.com/search?hl=en&gl=us&tbm=nws&q=apples&oq=apples"; URL url = new URL(urlquery); URLConnection connection = url.openConnection(); URLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5"); But, I don't know how to set the "User-Agent" parameters above. From where

Proxy With Java URLConnection class

坚强是说给别人听的谎言 提交于 2019-12-07 06:05:42
问题 I am very new with Java. I am using following code for the calling REST API, its working fine in simple environment but when I used with proxy environment Its throwing the NullPointerException . I found result on google that we have to set proxy setting for that. I set proxy according to that http://www.javaworld.com/javaworld/javatips/jw-javatip42.html article but this is not working + base64Encode( password ) creating syntax error. URL url = new URL("http://examplerestapi/get/user");

Why does HttpURLConnection.getResponseCode() throws IOException? [duplicate]

强颜欢笑 提交于 2019-12-07 04:08:23
问题 This question already has answers here : HttpURLConnection.getResponseCode() throws IOException when code is known (2 answers) Closed 3 years ago . I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException ? Am i missing something? 回答1: From javadoc: It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e

android使用HttpClient和URLConnection获取网页内容

一笑奈何 提交于 2019-12-06 20:28:45
今天开始android网络编程,平时做的android整机开发这块,基本上不大需要接触android网络变成这块知识,还是得熟悉熟悉。 本文要讲的是使用URLConnection对象和HttpClient组件访问网络以及获取 网页内容的方法。 Android对HTTP(超文本传输协议)提供了很好的支持,这里包括两种接口: 1、标准Java接口(java.net) ----HttpURLConnection,可以实现简单的基于URL请求、响应功能; 2、Apache接口(org.appache.http)----HttpClient,使用起来更方面更强大。一般来说,用这种接口。不过本文还是把第一种接口过一下。 任何一种接口,无外乎四个基本功能:访问网页、下载图片或文件、上传文件.本文示范的是访问网页和下载图片。HttpURLConnection继承自URLConnection类,用它可以发送和接口任何类型和长度的数据,且预先不用知道数据流的长度,可以设置请求方式get或post、超时时间。 先直接上代码吧: package com.example.webdatashow; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import

Simple java class to download the file

情到浓时终转凉″ 提交于 2019-12-06 12:23:33
问题 I am trying to download a file using simple java class using the following code: public class Download { public static void main(String[] args) throws Exception { Download d = new Download(); d.URLSetUp("http://www.sheldonbrown.com/web_sample1.html"); } public String URLSetUp(String urlProp) throws Exception { StringBuffer tempData = new StringBuffer(); String contentXML = ""; String line = ""; URL url1; try { url1 = new URL(urlProp); URLConnection conn = url1.openConnection(); conn

Can't get server certificate from site

泪湿孤枕 提交于 2019-12-06 12:06:38
I can't get the certificate from my website (neither other website). I tried some solutions with HttpsURLConnection and the method getServerCertificates but nothing solves the problem. URL httpsURL = new URL("https://www.google.com.br/"); HttpsURLConnection connection = (HttpsURLConnection)httpsURL.openConnection(); Certificate[] certs = connection.getServerCertificates(); I get an exception saying that "getServerCertificates cannot be resolved." I don't think its necessary to use keystore, is it?? I get an exception saying that getServerCertificates cannot be resolved.. That's strange. Are