Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSivadasVS committed Jun 24, 2020
1 parent 2f93684 commit c5ef013
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
public class PutData extends Thread {
private String url, method;
String result_data = "Empty";
String[] data, param;
String[] data, field;

public PutData(String url, String method, String[] param, String[] data) {
public PutData(String url, String method, String[] field, String[] data) {
this.url = url;
this.method = method;
this.data = new String[data.length];
this.param = new String[param.length];
System.arraycopy(param, 0, this.param, 0, param.length);
this.field = new String[field.length];
System.arraycopy(field, 0, this.field, 0, field.length);
System.arraycopy(data, 0, this.data, 0, data.length);
}

Expand All @@ -37,8 +37,8 @@ public void run() {
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, UTF8));
StringBuilder post_data = new StringBuilder();
for (int i = 0; i < this.param.length; i++) {
post_data.append(URLEncoder.encode(this.param[i], "UTF-8")).append("=").append(URLEncoder.encode(this.data[i], UTF8)).append("&");
for (int i = 0; i < this.field.length; i++) {
post_data.append(URLEncoder.encode(this.field[i], "UTF-8")).append("=").append(URLEncoder.encode(this.data[i], UTF8)).append("&");
}
bufferedWriter.write(post_data.toString());
bufferedWriter.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public void onClick(View v) {
public void run() {
//Starting Write and Read data with URL
//Creating array for parameters
String[] param = new String[2];
param[0] = "param-1";
param[1] = "param-2";
String[] field = new String[2];
field[0] = "param-1";
field[1] = "param-2";
//Creating array for data
String[] data = new String[2];
data[0] = "data-1";
data[1] = "data-2";
PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data);
PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", field, data);
if (putData.startPut()) {
if (putData.onComplete()) {
String result = putData.getResult();
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@
style="@style/Widget.AppCompat.Button.Colored"
android:theme="@style/Widget.AppCompat.Button.Colored"/>

<TextView
android:autoLink="web"
android:gravity="center"
android:layout_marginTop="5dp"
android:text="@string/github_vishnusivadasvs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">AdvancedHttpURLConnection</string>
<string name="data">Fetching Data</string>
<string name="data">Result Text</string>
<string name="fetch_data">Fetch Data</string>
<string name="put_data">Put Data</string>
<string name="github_vishnusivadasvs">GitHub.com/VishnuSivadasVS</string>
</resources>

0 comments on commit c5ef013

Please sign in to comment.