I am using WordPress in my site. The response I am getting from the server is HTML.
What do I need to do to get a server response in JSON format?
Have a look here Android HTTP Request for CakePHP URL , it's not exactly the same but to close to your question.
Related
I have a server I need to POST an http request to. The server is located at http://ec2-54-187-236-58.us-west-2.compute.amazonaws.com
I need to execute a POST /ios/search
I'm given that the HTTP body is a JSON dictionary but I cannot connect to the server itself. Nor am I able to see the JSON object in javascript when I enter the server url in a browser. I am using gson library in android to help me execute the http client request, but am getting the
IOException: Connection to http://ec2-54-187-236-58.us-west-2.compute.amazonaws.com/ios/search refused
What am I missing? Or is there an issue with the server url?
I have HTTP path that need to send JSON
{
"domain": "mas.org.il",
"params": {
"type":"hug"
}
}
to get another JSON with all items to insert into my Android app
How do I send this JSON to http URL and get JSON to parse it into my app.
please read this useful document to know how can you implementing this feature
https://www.itsalif.info/content/android-volley-tutorial-http-get-post-put
Just to give a vary basic idea,add the json in apache NameValue pair or use apache Entitys with HttpPost .. or you can follow this.
How To Send json Object to the server from my android app
I am working on payment integration with bank. When I do http post request with url and formencoded data , I am getting error html page. But if I am doing the same using webview , I am getting successul otp page of the bank. I am not sure why this response is different. As of now we have to do only http request and wanted the same response as returned by webview. I have tested same request in postman. I am getting successful otp page. What can be possible reason?
someone may asked my question already but I cannot find any suggestions.
I writing an Android app which needs to access my Django server by using HttpsURLConnection then Django server will return a JSON array to Android.
The view function in Django will receive the parameters from request.POST and generate the JSON array then return using HTTPResponse Django method. It does not need any Templates and Forms.
When I call the Django view function from Android, it returns 403 error. I know that it is because the POST data does not contains "csrf_token".
My problem is: How can I get the "csrf_token" and put it into my POST data before I send it to Django? I try disable the CSRF checking by "#csrf_exempt" it can return the correct result to Android app but I would not disable the CSRF checking.
Thanks,
Wilson
You have to send the cookies and also have to send a header 'X-CSRFToken' with csrftoken.
This is what I do (may not be the best way):
Get csrf token via a get request.But first try to see if you get a csrftoken cookie by doing same request on your browser with developer tools. If not, you should use ensure_csrf_cookie decorator
from django.views.decorators.csrf import ensure_csrf_cookie
#ensure_csrf_cookie
def your_view(request):
pass
Now using the same HttpUrlConnection object do this :
String cookieString="";
String csrftoken="";
// The below code can be shortened using for-each loop
List<HttpCookie> cookies=cookieManager.getCookieStore().getCookies();
Iterator<HttpCookie> cookieIterator=cookies.iterator();
while(cookieIterator.hasNext()){
HttpCookie cookie=cookieIterator.next();
cookieString+=cookie.getName()+"="+cookie.getValue()+";";
if(cookie.getName().equals("csrftoken")){
csrftoken=cookie.getValue();
}
}
Add the following to your post request:
urlConnection.setRequestProperty("X-CSRFToken", csrftoken);
urlConnection.setRequestProperty("Cookie", cookieString);
In my android application i would like to send a json object with username and password as string to the server.
Could you please let me know how i can achieve this using https connection.
Please share your valuable suggestions.
Thanks in advance :)
Have you tried a search?
Http Post in android
Android, sending XML via HTTP POST (SOAP)
Http post in Java
Http post in Java with UrlConnection
HttpClient android docs