public
class
MainActivity
extends
Activity {
String myId, myPWord, myTitle, mySubject, myResult;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button_submit).setOnClickListener(buttonClick);
}
Button.OnClickListener buttonClick =
new
Button.OnClickListener() {
public
void
onClick(View v) {
myId = ((EditText) (findViewById(R.id.edit_Id))).getText()
.toString();
myPWord = ((EditText) (findViewById(R.id.edit_pword))).getText()
.toString();
myTitle = ((EditText) (findViewById(R.id.edit_title))).getText()
.toString();
mySubject = ((EditText) (findViewById(R.id.edit_subject)))
.getText().toString();
HttpPostData();
}
};
public
void
HttpPostData() {
try
{
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setDefaultUseCaches(
false
);
http.setDoInput(
true
);
http.setDoOutput(
true
);
http.setRequestMethod(
"POST"
);
http.setRequestProperty(
"content-type"
,
"application/x-www-form-urlencoded"
);
StringBuffer buffer =
new
StringBuffer();
buffer.append(
"id"
).append(
"="
).append(myId).append(
"&"
);
buffer.append(
"pword"
).append(
"="
).append(myPWord).append(
"&"
);
buffer.append(
"title"
).append(
"="
).append(myTitle).append(
"&"
);
buffer.append(
"subject"
).append(
"="
).append(mySubject);
OutputStreamWriter outStream =
new
OutputStreamWriter(
http.getOutputStream(),
"EUC-KR"
);
Log.d(
"check"
,
"1"
+ myId);
PrintWriter writer =
new
PrintWriter(outStream);
Log.d(
"check"
,
"2"
);
writer.write(buffer.toString());
writer.flush();
Log.d(
"check"
,
"3"
);
InputStreamReader tmp =
new
InputStreamReader(
http.getInputStream(),
"EUC-KR"
);
BufferedReader reader =
new
BufferedReader(tmp);
StringBuilder builder =
new
StringBuilder();
String str;
while
((str = reader.readLine()) !=
null
) {
builder.append(str +
"\n"
);
}
myResult = builder.toString();
Log.d(
"check"
,
"Stirng"
+ myResult);
((TextView) (findViewById(R.id.text_result))).setText(myResult);
Toast.makeText(MainActivity.
this
,
"전송 후 결과 받음"
,
0
).show();
}
catch
(MalformedURLException e) {
}
catch
(IOException e) {
}
}
}