I am trying to hit this services but this gives me html reponse please help me where i am wrong
any help is really very help ful
HttpURLConnection connection;
java.net.URL u;
u = new java.net.URL("http://sdservices.iyogi.net/iyogi/webservicesnonrestv5/toolbarwebservices.asmx");
URLConnection uc = u.openConnection();
connection = (HttpURLConnection) uc;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("SOAPAction", "http://sdservices.iyogi.net/SD/ToolbarService.svc/GetProductSettings?SubscriptionCode=W101982488");
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");
InputStream is = connection.getInputStream();
inputStreamToString(is);
gives HTML in response:(
Related
I am new to android, i am using server call for signin with Basic Auth, its all works fine if i login with more than 45 letter in userid server response as Unauthorized. if user id is less than 45 letters its accepting
my server call as follows
HttpURLConnection conn=null;
URL url = new URL(url string);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setReadTimeout(60000);
String basicAuth = "Basic " + new String(Base64.encode(Username+":"+Password));
conn.setRequestProperty ("Authorization", basicAuth);
conn.connect();
Here conn.connect(); itself throws 401 : UnAuthorized
HttpURLConnection conn=null;
URL url = new URL(url string);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setReadTimeout(60000);
String publicKey = "Username:Password";//getting your key
String encodedString = Base64.encodeToString(publicKey.getBytes(), Base64.NO_WRAP);
String basicAuth = "Basic "+ encodedString; //space after Basic is matter.
//setting header for authentication purpose, should use authorization as keyword it you change this it won't work anymore
conn.setRequestProperty("Authorization", basicAuth);
conn.connect();
Code as below:
String credentials = String.format("%s:%s", "username", "password");
String basicAuth = "Basic "+ Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
HttpURLConnection conn=null;
URL url = new URL(url string);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setReadTimeout(60000);
conn.setRequestProperty ("Authorization", basicAuth);
conn.connect();
There is a strange problem when trying post some data to site with tilde.
How could I fix that in Android?
For example, this is my site:
http://host-site.com/~username/form.php
Here is my code for that:
url = new URL(hostSiteString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Host", "myHost");
urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0");
urlConnection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
urlConnection.setRequestProperty("Accept-Language", "en-US;q=0.7,en;q=0.3");
urlConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
urlConnection.setRequestProperty("Connection", "keep-alive");
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConnection.setDoOutput(true);
BufferedOutputStream bos = new BufferedOutputStream(urlConnection.getOutputStream());
bos.write(readyToken.getBytes(), 0, readyToken.length());
bos.flush();
bos.close();
Found solution, I had to decode my url.
String decode = URLDecoder.decode(hostSiteString);
url = new URL(decode);
So I am currently writing an android app that will get tweets from a particular user, using Twitter's 1.1 Application-only-auth, which requires a POST HTTP request to get a bearer token. I have a method set up that uses an HttpsURLConnection to open a connection, but
conn.setDoOutput(true); method isn't working
conn.doOutput stays false
the request stays the default GET.
Am I doing something wrong?
This method is called in an AsyncTask's doInBackground() method:
public String getRequestBearerToken(String endUrl) throws IOException {
String encodedCred = encodeKeys("API-key", "API-secret");
HttpsURLConnection connection = null;
try {
URL url = new URL(endUrl);
connection = (HttpsURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
// POST request properties
connection.setRequestProperty("Host", "api.twitter.com");
connection.setRequestProperty("User-Agent", getResources()
.getString(R.string.app_name));
connection.setRequestProperty("Authorization", "Basic "
+ encodedCred);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
connection.setRequestProperty("Content-Length", "29");
connection.setUseCaches(false);
...
I need to upload file to server using httppost type. In server side they received the file in httppostedfilebase instance.
How to do this? Suggest me.
try this:
url = new URL("http://....");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
outputStream = new DataOutputStream( connection.getOutputStream() );
outputStream.writeBytes(stufftosend);
outputStream.flush();
outputStream.close();
I am trying to connect to a server on port 8080 but AndroidHttpClient is forcing everything not on 8080 to use SSL. The offending code
URL url = new URL("http", "google.com", 8080, "");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.connect();
and this from Charles log.
note the URL field is using "https://"
now when I change the port to 80:
URL url = new URL("http", "google.com", 80, "");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.connect();
everything works fine:
I have no idea why it forces it to SSL when not on port 80. I had a similar issue with AndroidHttClient as well as DefaultHttpClient. Seems to be an issue with Android.