httpurlconnection

Adding body of call to POST using HttpURLConnection

大城市里の小女人 提交于 2019-12-19 11:54:15
问题 I am trying to use HTTPURLConnection make a POST method call to a server api. The JSON version of the body of my call is: { "grant_type" : "password", "username" : "perry.marange@zmod.co", "password" : "password" } How do I add this part using httpURLConnection? 回答1: i think you can use the Android Rest-Client for sending data to a webservice take classes RequestMethod.java and RestClient.java from this link https://github.com/TylerSmithNet/RESTclient-Android/tree/master/RESTclient-example

HttpURLConnection is throwing exception [duplicate]

情到浓时终转凉″ 提交于 2019-12-19 05:58:29
问题 This question already has answers here : How to fix 'android.os.NetworkOnMainThreadException'? (55 answers) Closed 6 years ago . Here is my code to connect HTTP . URL url = new URL("http://www.google.com"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDoOutput(true); String responseMsg = con.getResponseMessage(); int response = con.getResponseCode(); this is throwing android.os.NetworkOnMainThreadException Please help. 回答1: android.os.NetworkOnMainThreadException

Setting setChunkedStreamingMode in HttpURLConnection fails to deliver data to server

巧了我就是萌 提交于 2019-12-19 02:21:59
问题 My server version is as follows on my dev machine: Apache/2.2.21 (Win32) mod_fcgid/2.3.6 I have been testing HttpURLConnection as my project requires easy streaming capabilties. I have read a great synopsis from @BalusC on how to use the class. Using java.net.URLConnection to fire and handle HTTP requests The trouble I am currently having is when setting setChunkedStreamingMode . Regardless of what I set it to my stream doesn't seem to make it to the server the data stream is empty when my

Setting setChunkedStreamingMode in HttpURLConnection fails to deliver data to server

喜欢而已 提交于 2019-12-19 02:21:40
问题 My server version is as follows on my dev machine: Apache/2.2.21 (Win32) mod_fcgid/2.3.6 I have been testing HttpURLConnection as my project requires easy streaming capabilties. I have read a great synopsis from @BalusC on how to use the class. Using java.net.URLConnection to fire and handle HTTP requests The trouble I am currently having is when setting setChunkedStreamingMode . Regardless of what I set it to my stream doesn't seem to make it to the server the data stream is empty when my

Passing JSON data in get request as request body

时光毁灭记忆、已成空白 提交于 2019-12-18 15:52:12
问题 Hi i have to send a get request to an url http://onemoredemo.appspot.com/group?authToken=access_token&authMethod=oauth with request body contains json object as shown below. {"goupid":"some_variable" } Here is a section of java code for sending get request: URL url1=new URL("http://onemoredemo.appspot.com/group?authToken="+access_token+"&authMethod=oauth"); conn=(HttpURLConnection) url1.openConnection(); conn.addRequestProperty("Content-type", "application/x-www-form-urlencoded"); conn

HttpURLConnection Post: Output stream has no effect?

六眼飞鱼酱① 提交于 2019-12-18 13:38:00
问题 I am developing an Android app and have already found out that different Android versions have a different ways on how they handle Http(s)URLConnections (http://stackoverflow.com/q/9556316/151682). I ran into the issue that Android 4 performs a POST request over HTTPS nicely, adding headers like Content-Type automatically when running the code below. However, on Android 2.3.5 (device & emulator), any write to the output stream seems to be ignored - I debugged it with the web proxy Charles and

Android: HttpsUrlConnection with Authenticator for Basic Authentication iterates forever when password is wrong (on 401 response)

南笙酒味 提交于 2019-12-18 13:11:08
问题 I am using an HttpsUrlConnection with Basic Authentication by using an Authenticator and setting a default Authenticator object like this: Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("user", "userpass" .toCharArray()); } }); When I access my web-service the connection calls my getPasswordAuthentication() method to get the credentials and sends this to the web-server. This works allright as long

HTTP POST request with JSON String in JAVA

99封情书 提交于 2019-12-18 11:56:21
问题 I have to make a http Post request using a JSON string I already have generated. I tried different two different methods : 1.HttpURLConnection 2.HttpClient but I get the same "unwanted" result from both of them. My code so far with HttpURLConnection is: public static void SaveWorkflow() throws IOException { URL url = null; url = new URL(myURLgoeshere); HttpURLConnection urlConn = null; urlConn = (HttpURLConnection) url.openConnection(); urlConn.setDoInput (true); urlConn.setDoOutput (true);

Error for HttpResponseCode cannot be resolved to a type while checking URL status code for links

隐身守侯 提交于 2019-12-18 09:14:06
问题 I wrote simple program for checking URL status code. But eclipse giving me error saying HttpResponseCode cannot be resolved to a type. What should I do. import static org.testng.Assert.assertEquals; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa

How to show progress bar status by percentage while uploading json data?

天涯浪子 提交于 2019-12-18 07:42:49
问题 I am uploading string and photo.and its working fine. Now I want to show progress bar while uploading data with percentage but percentage show very quickly to 100 percentage and take some more time to upload and finally come to the post execute method. protected class upload_images extends AsyncTask<String, Integer, String> { ProgressDialog progressDialog; @Override protected void onPreExecute() { super.onPreExecute(); // showDialog(progress_bar_type); progressDialog = new ProgressDialog