Hi all :)
I got some serius problem that I've tried to solve in almost two days.
I've try to send a request to a URL from a android app, http://web.hjalmar.nu/~morgan/webpage/test.php. the problem is, that it isn't working.
ANDROID-file
package morgan.request.test;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
public class TestingrequestActivity extends Activity {
/** Called when the activity is first created. */
Button post;
EditText txt;
TextView outputt;
public String postData() {
String result = "";
try {
URL url = new URL("http://web.hjalmar.nu/~morgan/webpage/test.php");
URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.addRequestProperty("Http.host", "web.hjalmar.nu");
urlConn.addRequestProperty("Http.port", "80");
urlConn.setUseCaches(false);
DataOutputStream output = new DataOutputStream(urlConn.getOutputStream());
String content = "name=morgan";
output.writeBytes(content);
output.flush();
output.close();
DataInputStream in = new DataInputStream(urlConn.getInputStream());
BufferedReader input = new BufferedReader(new InputStreamReader(in));
String str;
while ((str = input.readLine()) != null) {
result = result + str + "\n";
}
input.close();
}
catch (MalformedURLException e) {
result = e + "\n";
}
catch (IOException e) {
result = e + "\n";
}
return result;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
outputt = new TextView(this);
outputt.setText(postData());
outputt.setHeight(10);
setContentView(outputt);
}
}
php-file:
<?php
echo "hello" . £_POST["name"];
?>
I get the error
java.net.UnknownHostException: web.hjalmar.nu
but the url is correct. you can try to click to the link to the php file.
I have taked the code from a tutorial site, so it chould work, but it don't.
I've quested a android programmer I know abaut the error, but he couldn't help
me.
can someone help me plz? you guys up there on daniweb is my only hope :S