httpurlconnection

Setting custom header using HttpURLConnection

此生再无相见时 提交于 2019-12-04 12:01:41
问题 I am simply making a GET request to a Rest API using HttpURLConnection . I need to add some custom headers but I am getting null while trying to retrieve their values. Code: URL url; try { url = new URL("http://www.example.com/rest/"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // Set Headers conn.setRequestProperty("CustomHeader", "someValue"); conn.setRequestProperty("accept", "application/json"); // Output is null here <-------- System.out.println(conn

java.net.SocketTimeoutException: timeout

醉酒当歌 提交于 2019-12-04 08:50:14
问题 With OkHttp library, application is facing following SocketTimeoutException issue. If request size is less, then it is working fine(Less than 1MB). I am getting this exception within 10 seconds, even my socket timeout( readTimeout ) value is much higher. It is consistently failing for a request(Size is 1.8MB). When I executed a request with HttpUrlConnection it is working fine. What could be a possible reason of failure? 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: java.net

authenticate with ntlm (or kerberos) using java UrlConnection

纵然是瞬间 提交于 2019-12-04 07:23:05
I need to consume a rest web service with java, passing the credentials of a domain user account. right now I'm doing it with classic asp set xmlHttp = server.createObject( "msxml2.serverxmlhttp" ) xmlHttp.open method, url, false, domain & "\" & user, password xmlHttp.send body out = xmlHttp.responseText set xmlHttp = nothing and with asp.net HttpWebRequest request = (HttpWebRequest) WebRequest.Create( url ); request.Credentials = new NetworkCredential(user, password, domain); request.Method = WebRequestMethods.Http.Get HttpWebResponse response = (HttpWebResponse) request.GetResponse();

HttpURLConnection conn.getRequestProperty return null

为君一笑 提交于 2019-12-04 06:56:08
I'm trying to push some data to an URL (MDS_CS) for a BES when i set some Request Headers in my code, and submit the request, the submited request's header is set to null . here is my code : HttpURLConnection conn =(HttpURLConnection)url.openConnection(); conn.setDoInput(true);//For receiving the confirmation conn.setDoOutput(true);//For sending the data conn.setRequestMethod("POST");//Post the data to the proxy conn.setRequestProperty("X-Rim-Push-ID", pushId); conn.setRequestProperty("Content-Type", "text/html"); conn.setRequestProperty("X-Rim-Push-Title", "-message"); conn.setRequestProperty

HttpURLConnection getting locked

半世苍凉 提交于 2019-12-04 06:51:02
I have a thread running under tomcat which creates a HttpUrlConnection and reads it through BufferedInputStream. After fetching data for some urls, it stalls. I got the jstack of the process which says HttpUrlConnection is locked and BufferedInputStream is also locked. "http-8080-1" daemon prio=10 tid=0x08683400 nid=0x79c9 runnable [0x8f618000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream

Java - sending HTTP parameters via POST method easily

久未见 提交于 2019-12-04 06:11:48
问题 I am successfully using this code to send HTTP requests with some parameters via GET method void sendRequest(String request) { // i.e.: request = "http://example.com/index.php?param1=a&param2=b&param3=c"; URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("GET"); connection.setRequestProperty("Content-Type", "text/plain"); connection

Does java.net.HttpUrlConnection always throw IOException if there is an error status return by Server?

扶醉桌前 提交于 2019-12-04 06:02:08
问题 I am using java.net.HttpUrlConnection to make Http request to my Server. I realized that if the Server return an error status (400 for example). HttpUrlConnection will throw an IOException corresponding to the error status. My question is: Does HttpUrlConnection always throw an IOException if the server return an error status (4xx, 5xx)? I take a look at HttpUrlConnection API description but I couldn't answer my question. Updated: Please see my test: public static void main(String[] args) {

How to kill a BufferedInputStream .read() call

心不动则不痛 提交于 2019-12-04 04:20:14
问题 I'm working on writing a program to download very large files (~2GB) from a server. I've written the program to be able to resume partially finished downloads, In order to simulate a bad internet connection, I've been pulling my ethernet cord out of my router while mid-download. Unfortunately, this causes my program to hang on the following call: while((bytesRead = in.read(data)) > 0) (Where bytesRead is an int, in is a BufferedInputStream built from an HttpURLConnection, and data is a byte

Not able to send additional parameters with image using HttpURLConnection in android

醉酒当歌 提交于 2019-12-04 04:05:56
问题 public class UploadProfilePicActivity extends Activity implements View.OnClickListener { ImageView imageView; Button btnUploadPic; Button btnskipUploadPic; Button btnSaveNContinue; private static int RESULT_LOAD_IMAGE = 1; String imagepath = null; ProgressDialog dialog = null; String url_profilePic; private int serverResponseCode; String api = "http://192.168.2.17:8000/api/v1/"; String format = "/?format=json"; AlmabayDatabase almabayDatabase; String encodedString; @Override protected void

[Android]-POST Json with HttpUrlConnection

淺唱寂寞╮ 提交于 2019-12-04 02:13:21
问题 I build a server side to my application when I send a requests to this server with python-script its work good, but with my app it doesn't work. Server: the server contains a database. when I send a JSON {"name":"your_name"} the server save in the DB the name. App(Android): @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonSend=(Button)findViewById(R.id.button_send); buttonSend.setOnClickListener