Lecture 10 Webserver
Lecture 10 Webserver
<?php
$abc = $_POST['username'];
echo $abc;
?>
PHP - GET and POST methods
The first method to pass information is through GET method in which $_GET
command is used. The variables are passed in the url.
The second method is to use POST method. The only change in the above
script is to replace $_GET with $_POST. In Post method , the variables are
not passed through URL.
Connecting via POST Method
The last thing you need to do is to write this data to the link. After writing , you need to open stream
to receive the responded data.
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( data );
MyTasl request;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
request.execute();
}
}
Complete Example (2/3)
public class MyTasl extends AsyncTask<String,String,String> {
@Override
protected String doInBackground(String... params) {
String Complete_line="";
try {
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data);
wr.flush();
@Override
protected void onPostExecute(String result){
this.roleField.setText(result);
}
Settings Wamp PHP Server
Instructions:
Wamp configuration. For PHP server:
->Right-Click-Wamp-green-icon>open Apache>click on httpd.conf.
->backup the original file contents.
->modify line 245 of .conf file add modifications.txt contents.
Now the system should work and server should give response.
If it doesn't or a forbidden exception is thrown;
Create a firewall inbound rule, on Port 80, for all connections.
see screen shots for firewall, name the rule,
Do keep in mind
->to disable the rule after testing your app, otherwise it could make your
computer vulnerable.
Repetition- Example
new SigninActivity(this,1).execute(username);
}
}
Repetition- Example
public class SigninActivity extends AsyncTask<String,Void,String>{
private Context context;
public SigninActivity(Context context,TextView statusField,TextView roleField,int flag) {
this.context = context;
}
@Override
protected void onPostExecute(String result){
this.statusField.setText("Login Successful");
this.roleField.setText(result);
}
.
.
.
.
.
//protected String doInBackground(String... arg0)
// Next Slide.
..
.
.
.
}
Repetition- Example
@Override
protected String doInBackground(String... arg0) {
try{
String username = (String)arg0[0];
String link="http://myphpmysqlweb.hostei.com/loginpost.php";
String data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(username, "UTF-8");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( data );
wr.flush();