using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
test : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
String result =
""
;
result +=
"HTTP METHOD:"
+ Request.HttpMethod;
result +=
"
"
;
if
(Request.Form.Count == 0)
{
result +=
"There is no form data
"
;
}
else
{
result +=
"FORM DATA:
"
;
foreach
(String key
in
Request.Form.AllKeys)
{
result += key +
": "
+ Request.Form[key] +
"
";
}
}
if
(Request.QueryString.Count == 0)
{
result +=
"There is no parameters in query string
"
;
}
else
{
result +=
"QUERY STRING PARAMETERS:
"
;
foreach
(String key
in
Request.QueryString.AllKeys)
{
result += key +
": "
+ Request.QueryString[key] +
"
"
;
}
}
Response.Write(result);
Response.End();
}
}
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class UploadDataToUrlActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.l1_upload_data_to_url);
// Create URI with some QueryString parameters
Uri uri =
new
Uri.Builder()
.scheme(
"http"
)
.authority(
"192.168.0.13"
)
.path(
"dotnetnuke/test.aspx"
)
.appendQueryParameter(
"param1"
,
"value1"
)
.appendQueryParameter(
"param2"
,
"value2"
)
.build();
try
{
// execute HTTP GET request
OutputStream response = HttpRequestGet(uri);
// Write output to screen
TextView txtResponseGet = (TextView)findViewById(R.id.l1_txtResponseGet);
txtResponseGet.setText(response.toString().replace(
"
"
,
"\n"
));
}
catch
(IOException e)
{
// do error handling here
}
try
{
// Create array list of form data
ArrayList formData =
new
ArrayList();
formData.add(
new
BasicNameValuePair(
"formData1"
,
"formValue1"
));
formData.add(
new
BasicNameValuePair(
"formData2"
,
"formValue2"
));
// execute HTTP POST request
OutputStream response = HttpRequestPost(uri,formData);
// Write output to screen
TextView txtResponsePost = (TextView)findViewById(R.id.l1_txtResponsePost);
txtResponsePost.setText(response.toString().replace(
"
"
,
"\n"
));
}
catch
(IOException e)
{
// do error handling here
}
}
// Method for sending HTTP GET request to a web page
public OutputStream HttpRequestGet(Uri uri) throws IOException
{
HttpGet httpget =
new
HttpGet(uri.toString());
HttpClient httpclient =
new
DefaultHttpClient();
HttpResponse response = httpclient.execute(httpget);
HttpEntity httpentity = response.getEntity();
if
(
null
== httpentity)
{
throw
(
new
IOException(
"HttpEntity is null"
));
}
ByteArrayOutputStream outstream =
new
ByteArrayOutputStream();
httpentity.writeTo(outstream);
return
outstream;
}
// Method for sending HTTP POST request to a web page
public OutputStream HttpRequestPost(Uri uri, ArrayList formData) throws IOException
{
HttpPost httppost =
new
HttpPost(uri.toString());
httppost.setEntity(
new
UrlEncodedFormEntity(formData));
HttpClient httpclient =
new
DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpentity = response.getEntity();
if
(
null
== httpentity)
{
throw
(
new
IOException(
"HttpEntity is null"
));
}
ByteArrayOutputStream outstream =
new
ByteArrayOutputStream();
httpentity.writeTo(outstream);
return
outstream;
}
}