I am trying to implement a VideoView that receives its content from a server. To get the content from the server, I need to set a custom header.
When trying to use the following function, with uri being the url and headers a hashmap containing my header ("testHeader", "testValue"):
videoView.setVideoURI(uri, headers);
it is not working as intended.
When I check the server, I can see that the headers are not set and I am unsure what the problem is.
Do the headers have to be in some kind of specific format?
Or any other ideas?
I already tried various formats for the hashmap values but in no case the header even appeared at the server.
I also saw this post but since you now can use
videoView.setVideoURI(Uri uri, Map<String, String> headers)
I found that answer to be outdated.
Edit: While doing further research, I found out that everything works as intended when I use my app on an Emulator running Android 11.
The issue only occurs when used from one particular device.
Related
The problem exactly like the following
I have one api which can provide some data and one apk,
I got my api response with my device and another different old response on the emulator with the same apk!
The emulator response is up to date with the latest changes while the other different response is before the changes.
The app uses retrofit without caching.
So what could be the problem?
Request contains only one header (access token)
Response contains headers like (ETag, Access-Control-Max-Age) but retrofit should not deal with them as there is no cache at all.
Screen shot from postman :
Also when waiting for a while all devices become up to date!
Are you sure with this?
The app uses retrofit without caching
Based on this https://github.com/square/retrofit/issues/678, I think that retrofit (OkHttp inside retrofit) caching your query.
You can change this behavior by 2 ways:
add ?_t=TIMESTAMP into your app query url
remove 'Access-Control-Max-Age' header from your server response
Or you can create new OkHttp client to retrofit and write something like that:
new OkHttpClient.Builder().cache(null).build();
or
Request.cacheControl(CacheControl.FORCE_NETWORK)
So what could be the problem?
If you dont' find the problem on the client, you should look for it on the server side. Any kind of caching (on the database, or on the HTTP response level) can show this behavior.
Without further knowledge about your setup and your test environment it is impossible to figure out what the problem could be. You write
Also when waiting for a while all devices become up to date
What does that mean? How do you determine, if your devices are up to date?
In your complicated case, with backend involved, you should provide an example project on Github where this behavior can be reproduced.
So, I'm currently developing an app for a service which has a json-based (unfortunately) read only API. Retrieving content is no problem at all, however the only way to post content is using a form on their site which location is a PHP script. The service is open source so I know which fields the form expects, but whatever I send, it always results in a BAD REQUEST.
I captured the network traffic inside my browser and as far as I can see, the browser constructs a multipart form request, however when I copy the request and invoke it again using a REST client, a BAD REQUEST gets returned.
Is there a way to construct a http request in Android that simulates a form post?
If it's readonly I think you wouldn't be able to make requests with POST (it's assume for editing or adding things).
If you let me make you an advise, I recommend you using this project as a Library.
https://github.com/matessoftwaresolutions/AndroidHttpRestService
It makes you easy deal with apis, control network problems etc.
You can find a sample of use there.
You only have to:
Build your URL
Tell the component to execute in POST mode
Build your JSON
As I told you, I don't know even if it will work.
I hope it helps!!!
We have a GWT app that accesses REST API. REST API is meant for other uses too, and is secured using JAAS basic authorization. GWT app uses RestyGWT dispatcher and filter, as shown here, to add Authorization: Basic to header, and, so far, this works fine.
However, our app also allows users to work with files, either download generated (such as pdf reports) or upload/download any kind files. We used servlets on server side for upload and download of these files, and Window.open() call to receive them in GWT. Without JAAS this worked fine.
Now I'm trying to secure that part of the API, too. Window.open(...) won't work because it doesn't allow for adding headers.
Is there some kind of workaround for this?
I've tried RequestBuilder, and I receive correct response, that contains the requested file. However, I'm not able to initiate the download of the file. Is it maybe possible to encode this (AJAX) response as data:... URL and display it using, for example, iframe, which will, in turn, initiate file download?
I always handled downloads by producing regular links. Wouldn't it be ok to check if a user session is valid and only then deliver the file?
By the way you could obtain an opened window's document and populate it:
public static native Document open(String url, String name, String features)/*-{
return $wnd.open(url, name, features).document;
}-*/;
I have implemented file download functionality in my application
navigateToURL(urlRequest,"_blank");
I am using navigateToURL method to call servlet in Java backed but in that case my URL contains values as in that URL request i am passing values in string and through get method i am downloading that file.
(like path of a file) so i need to hide that as it is security concern , please share your valuable comments.
You can use POST in Flex setting URLRequestMethod.POST to URLRequest.method();
This will hide your parameters from the eye, it's not a security solution, though.
Im trying to improve the Java Html Document a little but i'm running into problems with the HttpUrlConntion. One thing is that some servers block a request if the user agent is a Java VM. Another problem is that the HttpUrlConnection does not set the Referrer or Location header field. Since several sites use these fields to verify that the content was accessed from their own site, I'm blocked here as well. As far as I can see the only resolution is to replace the URL handler of the HTTP protocol. Or is there any way to modify the default HTTP Handler?
Open the URL with URL.openConnection. Optionally cast to HttpURLConnection. Call URLConnection.setRequestProperty/addRequestProperty.
The default User-Agent header value is set from the "http.agent" system property. The PlugIn and WebStart allow you to set this property.
If you use Apache HttpClient to manage your programmatic HTTP connectivity you get an extremely useful API which makes creating connections (and optional automatic re-connecting on fail), setting Headers, posts vs gets, handy methods for retrieving the returned content and much much more.
I solved my problem. We can just send the header to application/json and pass the body as a json object. That simply solves the issue.