I am trying to send data using the following url but Its somehow being declared invalid query in Logcat
Base_URI/users/add.json?json={“email”: xxx#x.com, “password”: “xxxxxxxxx”, “first_name”: “Xyz”, “last_name”: “Xyz”}
I have asked this question before but found no solution so I am being more specific now.
The web services are made in cakephp as far as I know. Its not accepting url because of this part "json={}". Also the parameters are separated by ',' rather than '&'. In short, what encoding should I use to get json from it ?
I get this error in Logcat:
Illegal character in query at index 56
one more thing, No suggestions for third party library unless there is no solution in org.apache.http . By the way I tried Volley Library but had no success.
Finally after debugging and trying different solutions the whole day, I solved my own problem :)
I needed to encode the parameters part and not the whole URL like this:
String url = "Base_URI/users/add.json?json=";
url =url + URLEncoder.encode("{\"email\":\""+email+"\",\"password\":\""+password+"\"}", "UTF-8");
Thanks everyone for taking part in it !
Try this:
Base_URI/users/add.json?json={"email": "xxx#x.com", "password": "xxxxxxxxx","first_name": "Xyz", "last_name": "Xyz"}
Related
I send an SMS saying "Click on https://www.example.com/?"
When I receive this SMS on an Android phone, only the https://www.example.com is clickable. The "?" is visible in the SMS, but is not part of the clickable URL.
Is there some way to escape the ? or do some other workaround so that click on the link goes to https://www.example.com/?
EDIT: Forget Android - even on this page on stackoverflow - the "?" is not part of the clickable link
Can you replace the question mark (?) by %3F
www.example.com/%3F
See:
https://www.w3schools.com/tags/ref_urlencode.asp
This appears to be correct behaviour (as far as I have observed on other systems) - an empty query string (effectively a dangling question mark) is not necessarily part of the URL so appears as punctuation.
As a workaround my suggestion is to ensure you always provide a parameter:
https://www.example.com/?a=a
Ideally you can find something that makes the link enticing to the user (rather than only confusing):
https://www.example.com/?vip=yes
Because these are not query parameters you are actually using, they should not affect your page processing
Hi you can send by converting to short url by https://goo.gl/ and you can get same as expected .
Please i am trying to send from an EditText a text with space between words but nothing inserted in my db !
and when i send a text with no space works and inserted !
please what is the problem here ??
MyAsyncTaskresources attemptLogin= new MyAsyncTaskresources();
attemptLogin.execute("http://xxx.xxxxx.com/add_demande.php?de="+infos_demande.getStringExtra("de").toString()+"&a="+infos_demande.getStringExtra("a").toString()+"&date="+infos_demande.getStringExtra("date").toString()+"&heur="+infos_demande.getStringExtra("heur").toString()+"&id_user="+infos_demande.getStringExtra("id_conducteur"+i).toString());
Have you try adding
N'
as a first part of the string?
You need to Encode the String values using URLEncoder.encode(<Query Value>,"UTF-8") before appending the values to the URL String.
MyAsyncTaskresources attemptLogin= new MyAsyncTaskresources();
attemptLogin.execute("http://xxx.xxxxx.com/add_demande.php?de="+URLEncoder.encode(infos_demande.getStringExtra("de").toString(),"UTF-8")+"&a="+URLENcoder.encode(infos_demande.getStringExtra("a").toString(),"UTF-8")+"&date="+URLEncoder.encode(infos_demande.getStringExtra("date").toString(),"UTF-8")+"&heur="+URLEncoder.encode(infos_demande.getStringExtra("heur").toString(),"UTF-8")+"&id_user="+URLEncoder.encode(infos_demande.getStringExtra("id_conducteur"+i).toString(),"UTF-8"));
First make your code readable, build your string before putting it in attemptLogin.execute(...)
now you have your string build you can check your string, try that and make sure your attemptLogin.execute() argument is a legit string!
using volley is best and fast than use this old process
volley library in android , can send request and get response easy and adding parameter such as string and no problem of space , and there is handle for server error to check where your error
I have a simple Google Places Query string from https://developers.google.com/places/web-service/search.
The following URL shows a search for restaurants near Sydney.
https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants+in+Sydney&key=YOUR_API_KEY
But then my retrofit2 & Okhttp3 encodes it like this below:
https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants%2Bin%2BSydney&key=YOUR_API_KEY
Replacing every occurrence of "+" with "%2B". And i wish to stop this.
How do I achieve this please?
Edit
I just finished reading the Github issue https://github.com/square/retrofit/issues/1407 , No answer found
does this work for you ?
Call<List<Articles>> getArticles((#QueryMap(encoded=true) Map<String, String> options);
encoded =true should tell retrofit that the paramter is already encoded.
I'm trying to filter a JSON url results using App Inventor 2, following sample codes from here1 and here2, but I still cannot get it done right. I only get one result at a time.
The JSON results are data in the form shown in the following figure:
{
"field1":"alphaNumeric1",
"field2":"aNumber1",
"field3":"DD/MM/YY",
"field4":"HH/MM/SS",
"field5":"https://",
"field6":"aText",
"field7":"aNumber2",
"field8":"alphaNumeric2",
"field9":"aNumber3",
"field10":"alphaNumeric3"
}
The JSON url is constantly updated, so are the results, but this is not a problem for now. I can get it read by a timer.
The problem is that from the above results, I need to parse "field2", "field5", "field6", in according labels in the app.
So e.g., when I input a "aNumber1" to get searched in the JSON data, and have the result in a label.
Is it possible this JSON data search be done with App Inventor 2?
Anyone kind enough please answer with a sample blocks if possible.
Thank you all in advance!
[EDIT 1]
No matter what I've tried, JSON could not get filtered right. Therefore I'm to filter the url results in XML.
The XML results are data in the form shown in the following figure:
<results>
<decision>
<alphaNumeric1>ABC1D</alphaNumeric1>
<aNumber1>ABCD</aNumber1>
<aDate>123</aDate>
<doc>HTTP</doc>
<aNumber2>1234</aNumber2>
<alphaNumeric2>TYPE</talphaNumeric2>
<aNumber3>12345</aNumber3>
<aNumber4>1234567</aNumber4>
<aText>SomeText</aText>
<aHour>00:00:00</aHour>
</decision>
.
.
.
<decision>
.
.
.
</decision>
.
.
.
</results>
I have tried to follow the example at here2, but I don't get it right. According to the XML output, what should I put in starTag and endTag, to get a parsing result if I'm searching for e.g. aNumber4 value (= 1234567) ?
Can someone respond with an answer?
[EDIT 2]
Well I'm trying to make some progress here following the example at here3.
The XML is being parsed with a runtime error "this is not a well formatted list of pairs".
Following is the blocks code I'm using:
Why is that so, since I'm following the example to the letter? Any clues anyone to solve this out?
well, your blocks look a little bit strange...
you have a complex list of lists, just use Do it to find out, how it looks like after each step of using lookup in pairs...
It helps to follow the already provided links:
how to work with lists
how to work with list of lists (pdf) by appinventor.org
see also An example of a complex List of Lists
In the example blocks below I looked for the first <decision> and displayed the value of tag aDate in Label1 like this
you might want to loop through the different <decision>s using a for each in list loop....
All I want to do is to send a URL String into my RESTFUL web service with some kind of code like this
URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText());
Its all going well until I found error with space character in my URL. I found some solution about replacing the space character with %20 which is I already defined with something like this :
URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText().replace(" ", "%20"));
Everything, again, seems going well until i found that the replace(Char oldChara, Char newChara) function can only replace ONE space character, and not two.
For brief example when I send the CharSequence.getText() with values "We won" there will be no error, but when I change the values into "We won the battles" there will be an error issuing that there are some illegal character sent to my RESTFUL web service.
Any kind of answer will come up with my great thanks and big salute
~Regards~
Use replaceAll instead of replace.
Although, you should really be doing proper URL encoding. You can use URLEncoder.encode
for example.