Android HTTP Link stop reading when there is a " ",() ,etc - android

I try to send the user key in String to onine server and make request, but it just send the string before the symbols. Any idea how to make Android read through but not remove the symbols? I mean all the symbols.
The following method is replace the [space] so the PHP can read my link
String sText = ""+autoTv.getText().toString().replace(" ","%20")+"";
SearchRequest t = new SearchRequest();
t.execute(sText);

Related

Android:Special characters are causing issue while passing to restful services

I have developed a restful service using C# .net,by using this service i have to validate the user login and password through android app developed in android studio.Now the password can contain special characters and in my case password is abc123* and URL become like this
http://srvcallnimbus.azurewebsites.net/srvcallnimbus.svc/validateuserByCompanyName/testPhone/test#test.biz/abc123
But this does not pass to the service correctly and my android app return error.I have tried all answers at stockoverflow.But abc123 dows not get into encoded form.URLEncoder.Encode(password) does not encode the * character.
I found a solution as follow
Following steps involve to solve above mentioned problem
Encode Your password in android app.
Decode your password in WCF restful service.
Encode Password in Android App.
Use the following method to encode your password in android app(encoding in base 64)
String base64Pass=""
string password="abc123*"
byte byteData[] =password.getBytes();
base64Pass= Base64.encodeToString(byteData, Base64.NO_WRAP);
Decode password in WCF restful service
Use the following way to decode your password in WCF Restful service.
String data = password; //passed as parameter
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char); //Decoded String

replace + with space in html Gmail/Android chrome

Hi i have web application which uses mailto like
Send email
but no meter what i do it alway replace space with + sign
Try to decode your String
just use Uri.encode(String).
subject = (EditText) findViewById(R.id.subject);
subject.setText(Uri.encode(WhatEverYourStringVarIs));
This will help you to decode the URIencode.
If you mean the PHP (HTML) Issue just do the same:
$encodeString = urlencode($encodeString);
echo $encodedString;
So the String will displayed proper.
See this url encode.
Okay, but when i'm read your Question the third time: You can use Spaces in these HTML case. It is an Android Bug. Just use this:
Send Mail

How to send Parameters (some values) from servlet to android

on the server side i am doing this and have to send three strings from this class
to the client side in android application
#Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException {
name1 = getParameter(req, "name");
phone1 = getParameter(req, "phone");
dob1 = getParameter(req, "dob");
String regId = getParameter(req, PARAMETER_REG_ID);
resp.setContentType("text/html");
Datastore.register(regId);
Datastore.register_name(name1);
Datastore.registerPhone(phone1);
Datastore.registerDob(dob1);
}
And On The Client Side I have to Recieve it
Actually i was doing it to get responses from server to client it has relay simple solution what you want to send from server to client side if you have post method in the do post method u have to make some output stream and what ever you write on the stream you can get easily by reading that output stream
yes u can use this way on servlet response
resp.setHeader(java.lang.String name, java.lang.String value)
and at Android end you can get the value from response
String value =response.getHeaders(name);
I hope u will get into the way i told u .....
Your question is not clear ...
Please edit your question and explain in detail
What I have understood is: You want to send some messages / parameters from your back end Server to the Mobile device.
If this is what you need, then have a look at the Google Cloud Messaging : http://developer.android.com/google/gcm/index.html which is designed specifically for this.

Mystery URL decoding of certain characters - Android URI / Google App Engine

I am having a curious problem that perhaps someone has insight into. I encode a query string into a URL on Android using the following code:
request = REQUEST_BASE + "?action=loadauthor&author=" + URLEncoder.encode(author, "UTF-8");
I then add a few other parameters to the string and create a URI like this:
uri = new URI(request);
At a certain point, I pull out the query string to make a checksum:
uri.getRawQuery().getBytes();
Then I send it on its way with:
HttpGet get = new HttpGet(uri);
On the Appengine server, I then retrieve the string and try to match the checksum:
String query = req.getQueryString();
Normally, this works fine. However, there are a few characters that seem to get unencoded on the way to the server. For example,
action=loadauthor&author=Charles+Alexander+%28Ohiyesa%29+Eastman&timestamp=1343261225838&user=1479845600
shows up in the server logs (and in the GAE app) as:
action=loadauthor&author=Charles+Alexander+(Ohiyesa)+Eastman&timestamp=1343261226837&user=1479845600
This only happens to a few characters (like parentheses). Other characters remain encoded all the way through. Does anyone have a thought about what I might be doing wrong? Any feedback is appreciated.
I never did find a solution for this problem. I worked around it by unencoding certain characters on the client before sending things to the server:
request = request.replace("%28", "(");
request = request.replace("%29", ")");
request = request.replace("%27", "'");
If anyone has a better solution, I am sure that I (and others) would be interested!
URLEncoder does not encode parentheses and certain other characters, as they are supposed to be "safe" for most servers. See URLEncoder. You will have to replace these yourself if necessary.
Example:
URI uri = new URI(request.replace("(","%28"));
If a lot of replacements are needed, you can try request.replaceAll(String regularExpression, String replacement). This, of course, requires knowledge of regular expressions.

How to get Hyperlink from whole string

I create an application in which i get the response from web service .
The response is
"I might be in danger. I have triggered my panic alarm which is connected to you. Call me now. If i'm not answering, contact the police. My position is:http://maps.google.com/maps?q=21.183783,72.823548"
3.I store the string in text view.and i want to open HTTP URL in browser,on the click of text.but how can i get HTTP URL in whole string plese give me idea.
You can do this easily with php...
If you are able to run php, this should do it.
$string = $_GET['string'];
OR
$string = $_POST['string'];
this may change depending on how you get the responce from the website, feel free to send me the form which you get the responce and ill change it accordingly.
$string_chunks = explode('http://',$string,2);
$url = 'http://'.$string_chunk['1'];
Basically, this will take the string, find the "http://" and create 2 strings out of it. one with the content before the "http://" and one with the content after, which is the url. so it would return $string_chunk['0'] and $string_chunk['1']
var response = "ur response string";
var indexofHttp = response.indexOf('http://');
var url = response.substring(indexofHttp);

Categories

Resources