why if i run this source , error FAILED EXCEPTION Asynctask #2 Illegal character in url
this is source
Intent in = getIntent();
get_nama = in.getStringExtra(tag_nama);
get_subkategoris = in.getStringExtra(tag_subkategoris);
"http://tribinacita.esy.es/tribinacita/index.php/sikomando/tampil_lokasi/?";
url += "nama_lok="+get_nama+"&subkategoris="+get_subkategoris+"&is_android=1";
"http://tribinacita.esy.es/tribinacita/index.php/sikomando/tampil_lokasi/?";
This line of code is just a string literal that isn't assigned to a variable. If this is identical to the code you are actually running, then you need to add an assignment:
url = "http://tribinacita.esy.es/tribinacita/index.php/sikomando/tampil_lokasi/?";
Related
Below is the HTML tag for the audio link url,
And below is the logic I used to get the URL,
String url = "https://www.dictionary.com/browse/happy?s=t";
Document doc = Jsoup.connect(url).get();
Elements wordBlock = doc.getElementsByClass("e16867sm0");
Element e = wordBlock.get(0);
Elements audioSection = e.getElementsByClass("e1rg2mtf7");
String audioUrl = audioSection.get(0).attr("audio");
But still I am unable to get the URL,
How can we get the URL of audio by using class id.
You can use either doc.select("source[type=audio/ogg]" for the first file or doc.select("source[type=audio/mpeg]" for the second one.
You can also use source[type^=audio] - it will give you both.
In my Android project I'm using Robospice with spring-android. Which works fine for all REST communication. But for the below request query parameter "=" is getting converted to "&". Because of this the request is getting failed.
Query String: tags=["keywords:default=hello"]
By checking the logs the request is converted as below for making call by the library.
http://XXX/rest/media/search?token=123&tags=%5B%22keywords:default&hello%22%5D
here "=" sign is converted to "&" in "keywords:default=hello"
Request Class
here tags = String.format("[\"keywords:default=%s\"]", mTag);
#Override
public MVMediaSearch loadDataFromNetwork() throws Exception
{
String search="";
if(!tags.equals(Constants.EMPTY_DATA))
search="&tags="+tags;
return getRestTemplate().getForObject( Constants.BASE_URL+"/media/search?token="+token+search, MVMediaSearch.class );
}
If I fire the URL in a browser, I'm getting error. And if I change the '&' sign to its corresponding url encoded value in browser, it works fine.
I also have the same issue.
For alternative, I use getForObject(java.net.URI, java.lang.Class).
URI uri = new URI(Constants.BASE_URL+"/media/search?token="+token+search);
getRestTemplate().getForObject(uri, MVMediaSearch.class );
http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/client/RestTemplate.html#getForObject(java.net.URI, java.lang.Class)
You can do something like this:
URI uri = new URI(
"http",
Constants.BASE_URL,
"/media/search?token=",
token,
search,
null);
String request = uri.toASCIIString();
take a look at THIS and see if you understand (you have to adapt to your code - this is not completely done for you)
After days of research and numerous compiler errors... i think i need some assitance from the community.
I have a simple app that retrieves a url through a shared intent from another app.
I want to extract a value from the intent's stringextra (which is a url) add it to the end of my script's url and send that final string as a URL to an URLconnection httpget request.
I've defined my script's url as a variable.
I've gotten the intent and its extras and put it in a variable.
I've tried to just concat my url variable and the stringextra variable to no avail,
URLconnectio gave me back a MalformedURLException. I've logged the concat'd variable
and it looked exactly like what i wanted but for some reason it wouldn't go through.
So now, I'm attempting to just cut the piece I need off of the stringextra and put it on my script's url and then make the http get request off that newly formed string.
SO....
how do I extract 11 characters after "v=", which is in the stringextra, which is
a variable called sharedText?
String goLoQooUrl = "http://my.domain.my/script.php?link=";
private static final String TAG = "LTV";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent rIntent = getIntent();
String rAction = rIntent.getAction();
String rType = rIntent.getType();
if (Intent.ACTION_SEND.equals(rAction) && "text/plain".equals(rType))
displaySentText(rIntent);
}
private void displaySentText (Intent rIntent) {
String sharedText = rIntent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText == null) return;
if (sharedText.startsWith("http://")) {
TextView url = (TextView) findViewById(R.id.URL);
url.setText(String.valueOf(sharedText));
****String w = goLoQooUrl+SUBSTRING***** this is what I want
Log.d("TAG", w);
};
playOnLoqooTv(w);
}
private void playOnLoqooTv (String w) {
try {
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
URL url = new URL(w);
I've tried numerous things to no avail
namely tried using the substring method and it gave me an error about that method
wasn't available I probably wasn't calling it correct.
Can any Masters of the Universes', shed some light?
Try this out:-
int indexOfv = sharedText.indexOf("="); // Get the index of =
indexOfv++; // To get the substring after this element.
String subString = sharedText.substring(indexOfv, indexOfv+11); //Get the 11 characters after the = sign.
I have a web service which returns an XML file like this:
<Service>
<id>12</id>
<function_code>2</function_code>
<cf>AABBBCCCAAA</cf>
<active>0</active>
<option>resume_state</option>
</Service>
In many case the element may be not returned, and the XML will be:
<Service>
<id>12</id>
<function_code>2</function_code>
<cf>AABBBCCCAAA</cf>
<active>0</active>
<option/>
</Service>
I'm parsing this element with the following code:
String id = response.getProperty("cf").toString();
String func= response.getProperty("function_code").toString();
int active = Integer.parseInt(response.getProperty("active").toString();
String option = response.getProperty("option").toString();
where response is SoapObject.
In this situation, when I try to print the option String on error line:
System.err.println("my option variable contains: "+option);
The result is:
my option variable contains anyType{}
Why? And what can I do for parsing the option string obtaining null value if the option element is void () ?
String appname = soapObject.getProperty("appname")
.toString();
if (appname.equals("anyType{}")) {
content.setAppname(null);
} else {
content.setAppname(appname);
}
You can try this, and it works fine..
When I try to shorten a link with "#,&" character I get an exception. Is there a way to handle these character properly?
This is a sample code that works:
String shortUrl = bitly.getShortUrl("http://z"); //Works
If I add for example '&' or '%25' to the string it will throw an exception:
String shortUrl = bitly.getShortUrl("http://z%26"); // Exception
String shortUrl = bitly.getShortUrl("http://z&"); // Exception
The getShortUrl function from this Java class.
Thanks
That library (the Java class you link to) doesn't escape the URL... that's pretty awful.
Excerpt:
private String getBitlyHttpResponseText(String urlToShorten) throws IOException {
String uri = getBitlyUrl() + urlToShorten + bitlyAuth;
HttpGet httpGet = new HttpGet(uri);
...
Notice how urlToShorten isn't escaped in any way, shape or form. Prone to injection-style attacks, and just generally doesn't work.
Anyway, you'll need to escape urlToShorten.