Reputation: 197
I am new to RESTful Web Service. Just wrote a very simple Android client (tested on phone) to request GET an online web services API from this link. Structuring online documentation for a REST API But it keeps returning cannot connect to the remote server. Really frustrating. Can any expert identify the problem here? Thank you very much.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView message = (TextView) findViewById(R.id.message);
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.thomas-bayer.com/sqlrest/CUSTOMER/3/", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int i, Header[] headers, byte[] bytes) {
message.setText(bytes.toString() + "/" + "Successfully connected to remote server.");
}
@Override
public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
message.setText("Cannot connect to the remote server.");
}
});
}
I was trying to connect to the web service generated by NetBeans Jersey from database(entities). My phone was connected to my laptop (where NetBeans web service was running, already check the status by opening glassfish portal http://localhost:4848, and I set the IP to 192.168.x.x something, no luck). I thought should find an easier, tested path such as this one. Still cannot connect to the remote server. Geez! I am using a indie made android http client from this guy http://loopj.com/android-async-http/
Upvotes: 0
Views: 1112
Reputation: 2075
I believe you have not see your Logcat properly. I tried your code and I found:
05-17 04:23:26.499: E/AsyncHttpRequest(5263): java.lang.SecurityException: Permission denied (missing INTERNET permission?)
05-17 04:23:26.499: E/AsyncHttpRequest(5263): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
Add <uses-permission android:name="android.permission.INTERNET" />
to your Manifest file and you should be all good :) Let me know if it helps!
Upvotes: 1