Hi everybody,
I'm trying to perform a web service call using a simple http request from an Android activity. The problem is that it works when the URL is NOT a microsoft webservice.
I use the following code to call the "http://www.google.com" page and it does work:
package com.android.myapp;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class lltask extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button loginButton = (Button)findViewById(R.id.loginButton);
loginButton.setOnClickListener(loginButtonListener);
}
private OnClickListener loginButtonListener = new OnClickListener() {
public void onClick(View v) {
EditText alertBox = (EditText)findViewById(R.id.alertBox);
try {
// Create a URL for the desired page
// Read all the text returned by the server
URL url = new URL("http://www.google.com");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
alertBox.setText("ok");
}
in.close();
} catch (Exception e) {
alertBox.setText("no");
}
}
};
}
So, when I click on the "loginButton", if I get a result, it returns "ok" in the "alertBox".
But, If I try to call this URL, an IOException rises:
http://myserver/Foobar/Services.svc/ReturnFooBar?arg1=foo&arg2=bar
It's very strange because when I type the URL in my browser, I get an answer.
Of course, I added the following line in the manifest:
<uses-permission android:name="android.permission.INTERNET" />
Did somebody try to perform such a web service call?
Thank you,
Regards