Skip to content

Commit

Permalink
success to send id and password
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichi10 committed Aug 30, 2015
1 parent 7406d6e commit 7469405
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public HttpCommunication(String serverName, String path){
mBuilder.path("/" + path);
}
//Uri for post
mUri = "http:" + serverName + "/" + path + "/";
mUri = "http://" + serverName + "/" + path;
}

public HttpCommunication(String serverName){
Expand Down Expand Up @@ -105,15 +105,20 @@ public String handleResponse(HttpResponse httpResponse) throws ClientProtocolExc
}).start();
}

public void Post() {
HttpPost request = new HttpPost(mUri);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse res = null;
try {
request.setEntity(new UrlEncodedFormEntity(postParams, "utf-8"));
res = httpClient.execute(request);
}catch (IOException e){
e.printStackTrace();
public String Post() {
Log.d("aaa", mUri);
Post post = new Post(mUri,postParams);
String res = "";
try{
Thread thPost = new Thread(post);
thPost.start();
thPost.join();
res = post.getResponse();

}catch (Exception e){

}
Log.d("aaa",res);
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package pmv02.ppr.yuichi10.github.com.joinevents;

import android.util.Log;

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.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.List;

/**
* Created by yuichi on 8/30/15.
*/
public class Post implements Runnable {
String mUrl;
List<NameValuePair> mParams;
String responseData = "nothing";
public Post(String url, List<NameValuePair> params){
this.mUrl = url;
this.mParams = params;
}

@Override
public void run() {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(mUrl);
try {
post.setEntity(new UrlEncodedFormEntity(mParams, "UTF-8"));// 文字コード変換
// リクエスト送信
HttpResponse response = client.execute(post);
// 取得
HttpEntity entity = response.getEntity();
responseData = EntityUtils.toString(entity, "UTF-8");

} catch(IOException e) {
e.printStackTrace();
}
Log.d("aaa", responseData);
}

public String getResponse(){
return responseData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void onClick(View v) {
case R.id.doSignIn:
//get server info
String server = DataManage.server;
String path = "/login";
String path = "login";
//get ID and password
String strID = idSignIn.getText().toString();
String strPass = passwordSignIn.getText().toString();
HttpCommunication hc = new HttpCommunication(server, path);
hc.setPostParameter("Id", strID);
hc.setPostParameter("Password", strPass);

hc.Post();
//if the password and ID was collect, go to Home activity
intent.setClassName(packageName, packageName + ".Home");
startActivity(intent);
Expand Down

0 comments on commit 7469405

Please sign in to comment.