I have integrated PayUMoney in my app using https://github.com/payu-intrepos/Android-SDK-Sample-App but there is need to add some URL in MainActivity like
//TODO Below url is just for testing purpose, merchant needs to replace this with their server side hash generation url
URL url = new URL("https://payu.herokuapp.com/get_hash");
and also
//TODO Deploy a file on your server for storing cardToken and merchantHash nad replace below url with your server side file url.
URL url = new URL("https://payu.herokuapp.com/store_merchant_hash");
in storeMerchantHash Function
//TODO Replace below url with your server side file url.
URL url = new URL("https://payu.herokuapp.com/get_merchant_hashes");
in fetchMerchantHashes function.
These type number of url, How i can get it?
I am not getting how to get this URL, kindly guide me.
Related
I can easily GET data through the following request:
https://api.instagram.com/v1/tags/nofilter/media/recent?access_token=my_access_token
using my web browser. And all data is correct.
But when I trying to request using Android
URL url = new URL(urlStr);
cn = (HttpsURLConnection) url.openConnection();
cn.setDoInput(true);
cn.setDoOutput(true);
cn.setRequestProperty("access_token", my_access_token );
cn.setRequestMethod("GET");
cn.connect();
I getting "405 Method not allowed" response. Why? How to access Instagram API through the Android.
Also I want to note that access token is getting well in same manner but with method POST and some output message (as described in manual), so I am sure that my_access_token is correct and up to date.
Best Regards
Ekaterina
Within my Android application I want to connect to a PHP file on my server/web host. Currently I cannot POST data to the PHP file, I think I am passing the URL in an incorrect format.
Using a Google URL as an example, would this be correct in order to establish the path to my PHP file?
URL url = new URL("http://74.125.224.72/myFile.php");
It seems that you have an extra space in your URL
URL url = new URL("http://74.125.224.72 /myFile.php");
must be
URL url = new URL("http://74.125.224.72/myFile.php");
EDIT You can also use the android Uri class and build it using the Uri.Builder
Uri uri = new Uri.Builder()
.scheme("http")
.authority("74.125.224.72")
.appendPath("myFile.php")
.build();
I have an project where I want to load some url came from webservice into a webView but. for that I am facing the following problem. Please help.
url = "www.facebook.com"
wv.loadUrl(url);
for above code I got an error say unable load webpage.
But if i changed this to
url = "https://www.facebook.com"
its working but I need to load url without having http or https mentioned .
Please help me on this.
add this by your own code like
String urlCameFromServer = "www.facebook.com";
if(!urlCameFromServer.contains("http")) {
urlCameFromServer = "http://"+urlCameFromServer;
}
wv.loadUrl(urlCameFromServer);
I have made an application for android with cordova, the homepage is in local and calls to web services through jQuery. The app has a plugin to view a PDF.
Now we want to see a PDF, but to see the pdf need to be log on the server. The login process done with jQuery and it works. Once we log on the server we can call services that require login.
The problem is that we want to retrieve a PDF that requires login, but the http session is not shared from jquery to cordova plugin (or webview). The request on the server is like a not log user.
We tried to recover PDFs do not need login and it works.
The plugin used is based on http://call-me-early.blogspot.com.es/2013/03/android-webview-download-pdf-generated.html
¿Any ideas?
We have tried to retrieve the pdf with jquery and pass the array of bytes to the plugin but does not work.
Another idea is to move the contents of the jquery's cookie to the plugin, but we can not get this cookie
Fixed. What we do is capture the cookie in the call (in success) that creates the session on the server. We keep the cookie locally and then send it to open the PDF plugin, this plugin adds the cookie to the call that makes the native part.
JS part:
success: _.bind(function(data, textStatus, request){
var header = request.getAllResponseHeaders();
console.log("header: "+header);
var match = header.match(/(Set-Cookie|set-cookie|Set-cookie): (.+?);/);
console.log("match: "+match);
if(match!==undefined && match!==null && match.length>=3){
console.log("CON COOKIE");
console.log("COOKIE: "+match[2]);
localStorage.setItem("miCookie",match[2]);
}
},this),
Plugin call
function callShowPdfPluginAndroid( param ){
require(['utils'], function(utils) {
utils.showLoading();
return cordova.exec( function(){utils.hideLoading();},
function(error){utils.hideLoading();nativePluginErrorHandler(error);},
"NativeBridgeAndroid",
"ShowPdf",
[param,localStorage.getItem("miCookie")]);
});
}
Native:
URL u = new URL(params[0]);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setRequestProperty("Cookie",cookie);
c.setDoOutput(true);
c.connect();
In my browser, or in iOS, when I try to get the contents of a URL with encoded http authentication information in the form
http://myUser:myPassword#www.example.com/secure/area/index.html
It just works. I'm getting URLs from a web service, and I'd like to avoid trying to parse them up for their HTTP auth info if I can help it. Is there a way to do something similar in Android without actually parsing the URLs? Alternatively, what is the best way to go about that?
UPDATE:
I find that when I try to set the authentication information in an Authorization header, I get a very strange FileNotFoundException.
Here's the code I'm using:
URL url = new URL(urlString);
URLConnection connection;
String authority = url.getAuthority();
if (authority.contains("#")) {
String userPasswordString = authority.split("#")[0];
url = new URL(urlString.replace(userPasswordString + "#", ""));
connection = url.openConnection();
String encoded = new String(Base64.encode(userPasswordString.getBytes(), Base64.DEFAULT), "UTF-8");
connection.setRequestProperty("Authorization", "Basic " + encoded);
} else {
connection = url.openConnection();
}
InputStream responseStream = connection.getInputStream();
All the info seems to check out, I've verified the url is correct, the base64 string is correct, and the file is certainly on the server--I have no trouble at all opening it with Firefox, and Firebug shows all the right headers, matching what I've sent as far as I can tell. What I get though is the following error (url host changed to protect the innocent):
java.io.FileNotFoundException: http://a1b.example.com/grid/uploads/profile/avatar/user1/custom-avatar.jpg
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1061)
Any idea what this is all about?
I looked into using HttpClient, but saw that in Issue 16041 it is recommended that we prefer URLConnection.
That looks like your browser is applying some extra rules to parsing the URL. In Android you can use HTTP Client's authentication mechanism such as BASIC and DIGEST to do the same things. Which one you choose is dependent on the server you are trying to authenticate against.
Here is a good page to get you started.
Unfortunately, on Android you can't pass the user info (username/password) in that format to either java.net.URL or HttpClient and have it work like in a browser.
I'd recommend using URI (see http://download.oracle.com/javase/1.5.0/docs/api/index.html?java/net/URI.html) to do this: pass your URL to the URI constructor that takes a String and then you can extract the user info (using getUserInfo()). You can then either use HttpClient's authorization classes (see http://developer.android.com/reference/org/apache/http/auth/package-summary.html) or build the basic auth header yourself (an example is given at http://www.avajava.com/tutorials/lessons/how-do-i-connect-to-a-url-using-basic-authentication.html).