Kotlin FileNotFoundException in URL - android

val sendlink=URL(
"$graphlink?grant_type=ig_exchange_token&client_secret=$Clientid&access_token=$shortlived")
return sendlink.readText()
ı want to make a Get Request and this is the easiest way( I have tried the as HttpUrlConnection it gives same error )
But this code give error like here :
java.io.FileNotFoundException: https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret={mysecret}&access_token={Token}

This kind of library gives FileNotFoundException Error for the request code 401 or higher.

Related

Android Volley: Bad URL in ImageRequest

I'm on Android Studio 4.1.3 (last release). I'm using the Android Volley library and I'm trying to retrieve an image from and API via ImageRequest. The URL that I'm using is the following one:
private String skinUrl = "http://crafatar.com/renders/body/680f95cff25d4f178fea90e2c003bebf.png?size=512&overlay&scale=7"
While using this url in the method
private void requestImage() {
RequestQueue requestQueue = Volley.newRequestQueue(this);
ImageRequest imageRequest = new ImageRequest(skinUrl, response -> skin.setImageBitmap(response),
0,
0,
ImageView.ScaleType.CENTER_CROP,
null,
error -> {
});
requestQueue.add(imageRequest);
}
I get this error message
NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.NetworkUtility.shouldRetryException(NetworkUtility.java:164)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:145)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
Caused by: java.net.MalformedURLException: no protocol:
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:498)
at java.net.URL.<init>(URL.java:447)
at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:82)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:104)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132) 
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111) 
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90) 
I've also tried to use the method URLEncoder
skinUrl = URLEncoder.encode(skinUrl);
but the result is the same.
The problem is only appening with the ImageRequest, because I'm also retriving json data from another API.
simple bro use glide image loading library
because its top of android and fast and efficient for image loading just you have to put your image URL and image is load but you have to apply internet permission in manifest.
visit doc - https://github.com/bumptech/glide

POST Request on kotlin

I am trying to execute a link so that I can control an ESP32 using Kotlin in Android Studio, but it is unable to execute it the same way a WebView can (I use the WebView to get a video feed, and it is able to transfer the video). The below is my code
Activity
val url = URL(ipcomm2)
val con: HttpURLConnection = url.openConnection() as HttpURLConnection
con.requestMethod = "POST"
WebView
setContentView(webview)
webview.loadUrl(IPfeed)
Can someone explain why this is the case? Thanks.
You need to call getInputStream and read it out.
See https://developer.android.com/reference/java/net/HttpURLConnection

Exoplayer gives errorcode 401

I am using exoplayer 2.7.3 and when i am trying to play some url i get below error:
E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 401
I can able to play same url in some other place in app. But at this place this issue happens.
Can anyone help me what might be wrong?
First, try to play the streaming on some web browser, if it fails, the problem is with this link.
The error 401 means that you not have permission to access this content.
Because you haven't set token for your data source. Set token like this :
// Create a data source factory.
val headersMap: MutableMap<String, String> = HashMap()
headersMap["Authorization"] = "Bearer ${"your token"}"
val dataSourceFactory: DataSource.Factory =
DefaultHttpDataSource.Factory().setDefaultRequestProperties(headersMap)

java.lang.IllegalArgumentException: Illegal URL with retrofit

i'm trying to call an api in my application
i've the following url template
test-test.domainname.com/feeds/json/v3/attribute/attribute
i'm using retrofit 2
but i get the following fatal exception
Illegal URL: test-test.domainname.com
and this is my interface
public interface Iinterface{
#GET("feeds/json/v3/attribute/"+attribute)
Call<ArrayList<result>>getresult();
}
can someone help me with this problem ...
my base URL is here: http://myapiname.azurewebservices.net
and feed method is like that :
public interface Iinterface{
#GET("/feeds/json/v3/attribute/"+attribute)
Call<ArrayList<result>>getresult();
}
And working perfectly. Please add http or https and try again
You do not have a protocol section. Prepend http:// or https:// depending on which applies to your url --
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://test-test.domainname.com")
// ... other retrofit options
.build();
In my case,
my base url contained space character. (eg. http://myapiname.azure webservices.net )
I fixed this Error by removing space in my base URL.
Illegal URL Exception in retrofit is triggered when your passed url is
not really existed or not fix with url standard.
By mistake, I provided empty string to baseUrl() so because of this i was getting java.lang.IllegalArgumentException: Illegal URL exception.

can't load open weather map icons

I am working with this http://www.survivingwithandroid.com/2013/05/build-weather-app-json-http-android.html tutorial to learn how use weather services in my app. I run this tutorial and it works fine. But I've got one problem. Can't load icons. Logcat error is
java.io.FileNotFoundExeption: http://openweathermap.org/img/w/ at libcore.net.http.HttpURLConnectionTmpl.getInputStream(HttpURLConnctionTmpl.java:186)
When I open this link in Chrome I can see the image so I don't know why it can't be found.
code is there https://github.com/survivingwithandroid/Surviving-with-android/tree/master/WeatherApp
Error in line 87 of file "WeatherHttpClient.java"
facing the same issue just change your url like bellow and its working fine
https://openweathermap.org/img/wn/50d#4x.png
You're trying to load a directory as file stream. Not sure why this should cause a FileNotFoundException but it's worth trying with the URL: http://openweathermap.org/img/w/<one-of-the-files>.png
At least the file should be possible to open.
add .png file ext
example
con = (HttpURLConnection) ( new URL(IMG_URL + code +".png")).openConnection();

Categories

Resources