i am creating android app where i need to pass url with port as "http://182.71.155142:8888" but when i request for this url from android app using loopj Library .It shows me exception and Exception is:
Unable to resolve host "nsg-static-142.155.71.182.airtel.in": No address associated with hostname
Can anyone help me how to pass port number so that i can get response from url
i am sending the request by using following code:
AsyncHttpClient client = new AsyncHttpClient(8888);
client.get("http://182.71.155.142/demo/loan-lelo/json/1",params,new AsyncHttpResponseHandler()
i am able to hit url from browser and getting response
by this way i am hitting url "http://182.71.155.142:8888/demo/loan-lelo/json/loan-details/1"
Try using any other library. I tried with OKHttp Library and works properly for me in my case.
Related
I use the INTERNET uses-permission in the manifest file.
If I type URL url = new URL('http://www.example.com/page') (remote server) it will work.
But if I type URL url = new URL('http://example.local/page') (local server) it will return the error
java.net.UnknownHostException: Unable to resolve host "example.local": No address associated with hostname
Now in %WINDIR%/System32/drivers/etc/hosts I wrote this entry :
10.101.0.179 example.local
I can't use new URL('http://10.101.0.179/page') because example.local is a virtualHost in my apache configuration.
Can't my AVD looks into the hosts file ? what should I do to tell android to fetch the ip 10.101.0.179 but still send a proper information to apache and tell it to serve the virtual host example.local ?
If you try to request a web-page from your local HTTP server and the page is bounded to a virtualHost, so let say you need to reach http://example.local/mypage and if as pointed by #CommonsWare you don't use mDNS to resolve inter-local domain-names, android will probably throw the same error message as it reads in the title of this question. Here's the solution I am using :
let's say http://example.local/mypage refers to the ip address 10.101.0.179, Android won't be able to resolve example.local, you need to write the raw url (of your actual local server)
try {
...
URL url = new URL("http://10.101.0.179/mypage");
HttpUrlConnection conn = (HttpUrlConnection) url.openConnection();
...
}
...
But now when Apache receives this request, unless serving your desired host, 10.101.0.179 won't be understood in case of a VirtualHost. To round-about this problem, just modify the Host http-header property using setRequestProperty :
...
conn.setRequestProperty("Host", "example.local");
...
And it should work.
First you must check if you have given INTERNET permission in your manifest file or not, second you make sure that your emulator or computer has a valid internet. If it doesn't work than you can do following:
If you are using localhost url than you must convert that url into IP address to work with App specially using Android emulator.
For example :
My Current url is
http://mylocaladdress:9090/myapp.svc/ForgetPassword?EmailID=test#test.com
Now you can put the following command into terminal on mac or you can use cmd on windows
ping mylocaladdress
The result will give u the IP address and my final url becomes
http://10.1.2.111:9090/myapp.svc/ForgetPassword?EmailID=test#test.com
This url worked perfectly in android emulator without exception.
Unable to resolve host name exception during sending first http request using android volley through my app to AWS(Amazon) where my Java Web Application is hosted. But when I request from mobile browser to the same link then it respond and after this through app also it responds. Please help me out from this problem.#AWS#
I have an android application where I have authentication and authorization services. Recently we had to change our URL's from http to https. I really don't want to resubmit app to the app store with urls changed to https.
Main problem I am facing is, asynchttpclient returning status code 200 without response, why I am not getting 301 which I am getting when I try to call service through advanced rest client.
I tried this already:
aesHttpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);
I want to know how can I redirect in asynchttpclient?
Please help
AsyncHttpClient client = new AsyncHttpClient();
client.setEnableRedirects(true);
I want to get the network response code of server in webview/BrowserFrame/WebViewClient.
Eailer it was working fine until 2.3 but from 3.0 /4.0 WebViewClient API(onReciveError) is not working and No http resource response is available in app.
I there any other alternative to recive it whenever I pass a url to webview.
I'm building an Android app that runs off of a rails server. At first, when I tried to post simple String data to the server, I ran into an InvalidAuthenticityToken issue, but realized that I can bypass the authentication by setting the content type to "json"
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(Constants.REST_HOST + "/add_comment");
post.addHeader("Content-Type", "application/json");
The next step was trying to get upload profile picture working. However, when I tried uploading a photo via a MultipartEntity post, setting the content type to "json" causes the following error
StandardError (Invalid JSON string):
but not setting the content type brings back the InvalidAuthenticityToken exception. What's the correct way to post an image to a rails server from a foreign Java client?
ActionController::InvalidAuthenticityToken
(ActionController::InvalidAuthenticityToken):
Based on Jesse's suggestion, I ended up using
protect_from_forgery :except => :upload_avatar_pic
to disable authenticity check, but only for a specific function, so checks for browser requests are still validated.
You can disable authenticity checking on API non-get calls from non-web clients. You can do this in a before filter
class ApiController < ApplicationController
skip_before_filter :verify_authenticity_token
def create
#or whatever
end
end
The problem solved by Jesse Wolgamott said, but the page show "You are being redirected" message when I submit the form (Update,create,show). In before that the page redirected correctly. I am using rails 2.3.8.how to resolve this?