Unable to set Cookie with httpclient Android - android

cookies are not being set , below is the code.
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPostRequest = new HttpPost(URL);
CookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie("Name", "value");
cookieStore.addCookie(cookie);
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
httpPostRequest.setEntity(fileentity);
HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest,localContext);
have also tried
httpclient.setCookieStore(cookieStore);
but nothing works .

Related

nullToken scope not set. This request does not have the required privilege

In the use of Autodesk's AndroidSDK, the token was successfully obtained; but at Create Bucket, unexpectedly returned “nullToken scope not set. This request does not have the required privilege.”
code:
HttpPost request = new HttpPost(BASEUrl+ upload_srv);
request.addHeader("Content-Type", "application/json");
//v2 changed the param name from 'policy' to 'policyKey'
String jsonstr ="{\"bucketKey\":\""+ newBucketName + "\", \"servicesAllowed\":{}, \"policyKey\":\"temporary\"}";
HttpEntity jsonent = new StringEntity(jsonstr,HTTP.UTF_8);
request.setEntity(jsonent);
HttpClient httpclient = getNewHttpClient();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, globalcookies);
HttpResponse response = httpclient.execute(request,localContext);

How to use OkHttpClient on below Apache HttpClient code

HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPut put = new HttpPut("url");
put.addHeader("X-Apikey","");
StringEntity se = new StringEntity( version.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
put.addHeader("Accept", "application/json");
put.addHeader("Content-type", "application/json");
put.setEntity(se);
try{
HttpResponse response = httpClient.execute(put, localContext);
HttpEntity entity = response.getEntity();
Here, I need a help to replace HttpClient with OkHttpClient with its all subsequent parameters.
The okhttp-apache module let's you do this:
HttpClient httpClient = new OkApacheClient();
It doesn't do everything Apache HTTP client can do, but it does make it easier to migrate.

Android How to save cookies on sdcard using HttpClient

I need to know a way to store my HttpClient cookieStore on a txt file as a string and how to re-use those and make a new httpConnection.
httpclient=new DefaultHttpClient();
cookieStore = new BasicCookieStore();
localContext= new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

Get return url from HttpPost

How can i get return URL from HttpPost. I'm using this:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(SERVER_ADDRESS);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2)
blablabla adding pairs...
HttpResponse httpResponse = httpclient.execute(httppost);
The page i request redicts me to another one and i want to know it's url
Thanks

how to send rest data using httppost in android

I am developing a hotel booking app using expedia. I need to send the following rest data to server using the httppost
http:/api.ean.com/ean-services/rs/hotel/v3/list?minorRev=[current minorRev #]
&cid=55505
&apiKey=xxx-yourOwnKey-xxx
&customerUserAgent=xxx
&customerIpAddress=xxx
&locale=en_US
&currencyCode=USD
&city=Seattle
&stateProvinceCode=WA
&countryCode=US
&supplierCacheTolerance=MED
&arrivalDate=09/04/2012
&departureDate=09/05/2012
&room1=2
&numberOfResults=1
&supplierCacheTolerance=MED_ENHANCED
String urlToSendRequest = "https://example.net";
String targetDomain = "example.net";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpHost targetHost = new HttpHost(targetDomain, 80, "http");
HttpPost httpPost = new HttpPost(urlToSendRequest);
httpPost.addHeader("Content-Type", "application/xml");
StringEntity entity = new StringEntity("<input>test</input>", "UTF-8");
entity.setContentType("application/xml");
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(targetHost, httpPost);
Reader r = new InputStreamReader(response.getEntity().getContent());

Categories

Resources