Upload file via POST request without HttpClicent - android

As I read, HttpClient is deprecated since Android API 22. That's why I don't want to use it. I need to upload file vie POST request with possibility to track upload progress. Is there way to do it?

You can use HttpUrlConnection with Asyctask to show progress.
Also you can refer this link for the same.

Related

Send an image to a server using HttpURLConnection

I have to send an image to a server (I think the best option is using HttpURLConnection) and recieve from it a String answer. In the different docuemnts and web sites that I have read, I have investigated that the best way to do this is using MultipartEntity.
1_ Is it the best solution to do it?
2_ I had an error which says that Android Studio cannot resolve the symbol 'MultipartEntity'. I read that to solve it I have to download external libraries. Which are them and how can I download them?
3_ For this I want to run this process in backGround, but I have a mistake writing the AsyncTask like AsyncTask<String, Void, String> because I want to recieve the parameters like in the answer from this question (Sending files using POST with HttpURLConnection): String urlString, MultipartEntity reqEntity. How can I do to resolve it?
I think the best option is using HttpURLConnection
Is it the best solution to do it?
Probably not. It's too low-level for multi-part requests.
I had an error which says that Android Studio cannot resolve the symbol 'MultipartEntity'. I read that to solve it I have to download external libraries. Which are them and how can I download them?
Options include, but not limited to
Apache HTTP (which is where MultipartEntity comes from)
OkHttp with a multipart example
VolleyPlus
You can get either using Gradle. For Apache see: Android - MultipartEntity and dependencies, and Okhttp just read their documentation where it says "Gradle"
For this I want to run this process in Background
Can't remember about Apache, but OkHttp already can handle that without an AsyncTask.

Volley upload file/image without using httpcilent

as MultipartEntity is removed from sdk 23 what is best way to upload images with other string params to server .
i did refer How to upload file using Volley library in android? but here only file are present
how i can upload image using volley
Use this below link. You can know more about volley
http://www.androidhive.info/2014/05/android-working-with-volley-library-1/
Retrofit is another rest client to know more about retrofit see the below link
http://square.github.io/retrofit/

Calling Nest REST API on from android app without using Firebase SDK

Including Firebase.jar file in my android app project will cause reaching 64k dex limit. So, I'd like to use REST API instead of Firebase API.
After I got access token, I try to use either HttpPut or HttpsURLConnection to change thermostat mode. By using HttpsURLConnection, I got http response code 307 to ask me to redirect to firebase-apiserverN url. Then, I use the new URL and do a HttpsURLConnection PUT, I got http response code 400.
Is there any Nest API sample code for android without Firebase? Thanks.

Google Safe Browsing API v2 sample Implementation Android

I am trying to implement a Sample application in Android which gets the malware and phishing list from safe Browsing API and checks the authenticity of URL, this is client side method, but I am constantly getting 400 (Bad Request) as response code when I am trying to hit the URL.
Searched throughout the internet but couldn't get any sample working code.
Even on Developer's Guide page https://developers.google.com/safe-browsing/developers_guide_v2 it is not mentioned how to send the list name correctly in POST request for downloading or updating.
Please help me by providing the correct procedure of how to send list name (if code snippet can be posted, it would be great as I am new to Android.)
Check out that request should end with '\n'. It is common to ignore this. I hope it helps.

HTTP GET url with Json parameters in Android

I am having the following API call:
http://rollout.gr/api/?query={%22search%22:%22places%22,%22page%22:1}
This API call is executed correctly in my browser. But when I use a DefaultHttpClient to execute this url in my Android application, I get a null response.
I suppose the problem is the JSON data in the HTTP url. Thus, I would like to ask which is the proper way to handle such url in an Android application?
Thanks a lot in advance!
The accolades aren't valid URL characters. The browser is userfriendly enough to automatically URL-encode them, but DefaultHttpClient isn't. The correct line to use from code is:
http://rollout.gr/api/?query=http://rollout.gr/api/?query=%7b%22search%22:%22places%22,%22page%22:1%7d
Note the encoding for the accolades (%7b, %7d).
Your problem may be the strictmode here.
I recommend to do http request in threads or asynctasks. strictmode doesnt let app do http reauest in uithread. maybe your console shows a warning and you get null from http response because of this.
This project may solve your problem:
http://loopj.com/android-async-http/
Not knowing your particular HTTP initialization code, I'm going to assume you didn't provide an explicit JSON accept header. A lot of REST endpoints require this.
httpget.setHeader("Accept", "application/json");

Categories

Resources