httpurlconnection

doInBackground not updating variable

人走茶凉 提交于 2019-12-23 06:16:23
问题 I'm working on a basic android app that makes a POST with HttpURLConnection . I want to return the response Message from my Web API. My MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView mTextView = findViewById(R.id.textView); AsyncExample asyncExample = new AsyncExample(); asyncExample.execute(); mTextView.setText

Android HttpUrlConnection

时光总嘲笑我的痴心妄想 提交于 2019-12-23 06:14:43
问题 I am new to Android development and I observed that HttpClient has been deprecated in API 22 .then I found that HttpUrlConnection is supported by Android.I searched for many tutorials but I am not able to find solution for sending post parameters in JSON format to a PHP script . Guide me the way to solve that problem. 回答1: You can used the following asynchronous method . public class BackgroundActivity extends AsyncTask<String,Void,String> { @Override protected String doInBackground(String...

How to use Cookies in HttpURLConnection for ANDROID?

徘徊边缘 提交于 2019-12-23 03:36:32
问题 I am trying to create an Application for Asterisk Interface, the configuration setup has been done properly as I have double checked it. It seems the reason why I can't access Config files from Asterisk server has to do with the connection. I need to use a cookie for connecting to the same instance of the login session. But so far I am unable to use Cookie Properly need a little help. I am supposed to login by pressing button1 (bt1) and get config file by pressing button2 (btn2). public class

HttpURLConnection - Lots of requests

血红的双手。 提交于 2019-12-23 03:24:09
问题 I have written a service which is used to register some data. That service can be called thousands of times. The parameters are passed via the URL itself. The client part of it looks something like this: private String getNodeInfoFromGPSForSpecificSubscriber( int subscriberId ) throws Exception { String requestURLToNode = "http://" + GPSConstants.GPS_IP + ":" + GPSConstants.PORT_NUMBER + APIs.FetchASpeecificNodeAPI.FETCH_A_SPECIFIC_NODE + "?" + APIs.FetchASpeecificNodeAPI.SUBSCRIBER_ID + "="

HttpURLConnection doing a get request even after setDoOutput(true), setRequestMethod(“POST”) setRequestProperty("Content

孤街浪徒 提交于 2019-12-23 02:36:58
问题 Here is the code: String Surl = "http://mysite.com/somefile"; String charset = "UTF-8"; query = String.format("param1=%s&param2=%s", URLEncoder.encode("param1", charset), URLEncoder.encode("param2", charset)); HttpURLConnection urlConnection = (HttpURLConnection) new URL(Surl + "?" + query).openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setAllowUserInteraction(false); urlConnection.setRequestProperty(

JAVA: How to create http url connection selecting the ip address to use

旧城冷巷雨未停 提交于 2019-12-22 17:28:22
问题 I have a pool of public ip addresses configured on my multiple NICs. In my JAVA project, which runs on a LINUX machine, I need to select a specific ip address from the pool and create an HttpURLConnecion using that ip. Further, I will cycle on the pool, using each time a different ip. At the current stage, I was not able to find a solution using the java.net library. I have rather looked at the HttpClient from Apache. At the following link, http://hc.apache.org/httpcomponents-client-ga

Send GET request with token using Java HttpUrlConnection

假如想象 提交于 2019-12-22 10:27:27
问题 I have to work with RESTful web service which uses token-based authentication from Java application. I can successfully get token by this way: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public void getHttpCon() throws Exception{ String POST_PARAMS = "grant_type=password&username=someusrname&password=somepswd&scope=profile"; URL obj = new URL("http://someIP/oauth/token");

How to get Cookies with HttpURLConnection in Java?

强颜欢笑 提交于 2019-12-22 09:57:51
问题 When I use HttpURLConnection and try con.getHeaderField("Set-Cookie") I get this response: __cfduid=1111111aaaaaa; expires=Wed, 19-Dec-18 06:19:46 GMT; path=/; domain=.site.com; HttpOnly But the browser cookies are: __cfduid=1111111aaaaaa; _ym_uid=000000000; PHPSESSID=zzzzzzzz; _ym_isad=1; key=555 How I can get the FULL cookie, using HttpURLConnection ? The most important cookie for me is key . 回答1: The value of Set-cookie header modify or append new value to Cookies in browser. And browser

Getting http 407 error as an IOException

巧了我就是萌 提交于 2019-12-22 09:14:01
问题 I'm using in my android application the HttpURLConnection through a proxy where an authentication is needed. Here is my code and I will explain you after my problem. HttpURLConnection connection = null; int responseCode = -1; try { connection = (HttpURLConnection) myUrl.openConnection(); connection.setInstanceFollowRedirects(false); connection.setConnectTimeout(DEFAULT_TIMEOUT); connection.setReadTimeout(DEFAULT_TIMEOUT); responseCode = connection.getResponseCode(); System.out.println(

Android - Using HttpURLConnection to POST XML data

痞子三分冷 提交于 2019-12-22 09:11:54
问题 I've run into a bit of a deadend and need a bit of help (please)! I'm very new to Android Dev (and to coding in general). Basically I need to POST XML data to a URL using HttpURLConnection but can't get it to work. I've got my app reading and pasrsing XML data from a GET request but finding the POST part difficult. I've looked at creating a NameValuePair array but not sure how to do this with the XML structure I am needing to post. The XML data will look like this: <Sheet> <Job>jobNumber</Job