그래서 이것을 테스트하기 위해 here에서 소스 코드를 얻었고 서버에서 출력 또는 응답을 얻지 못했습니다. 왜 이런 일이 일어나는 지 아는 사람이 있습니까? 나는 두 번째 "시도"에서 무언가가 작동하지 않고 그 안에 아무것도없는 exclusion ex에 들어가는 느낌을 가지고있다. 이 올바른지? 어쨌든 저에게 응답/결과를주기 위해 저를 도와주십시오.메신저와 같은 출력을 얻지 못했습니다
public class HttpPostExample extends Activity {
TextView content;
EditText fname, email, login, pass;
String Name, Email, Login, Pass;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_http_post_example);
content = (TextView)findViewById(R.id.content);
fname = (EditText)findViewById(R.id.name);
email = (EditText)findViewById(R.id.email);
login = (EditText)findViewById(R.id.loginname);
pass = (EditText)findViewById(R.id.password);
Button saveme=(Button)findViewById(R.id.save);
saveme.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
try{
// CALL GetText method to make post method call
GetText();
}
catch(Exception ex)
{
content.setText(" url exeption! ");
}
}
});
}
// Create GetText Metod
public void GetText() throws UnsupportedEncodingException
{
// Get user defined values
Name = fname.getText().toString();
Email = email.getText().toString();
Login = login.getText().toString();
Pass = pass.getText().toString();
// Create data variable for sent values to server
String data = URLEncoder.encode("name", "UTF-8")
+ "=" + URLEncoder.encode(Name, "UTF-8");
data += "&" + URLEncoder.encode("email", "UTF-8") + "="
+ URLEncoder.encode(Email, "UTF-8");
data += "&" + URLEncoder.encode("user", "UTF-8")
+ "=" + URLEncoder.encode(Login, "UTF-8");
data += "&" + URLEncoder.encode("pass", "UTF-8")
+ "=" + URLEncoder.encode(Pass, "UTF-8");
String text = "";
BufferedReader reader=null;
// Send data
try
{
// Defined URL where to send data
URL url = new URL("http://androidexample.com/media/webservice/httppost.php");
// Send POST data request
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null)
{
// Append server response in string
sb.append(line + "\n");
}
text = sb.toString();
}
catch(Exception ex)
{
}
finally
{
try
{
reader.close();
}
catch(Exception ex) {}
}
// Show response on activity
content.setText(text );
}
}
편집 : 난 그냥, 사람이 어디에 정확히 알고 디버깅을했고, 내가 문제가 여기에서의 어딘가에 thwere에 대한 권리 것을 발견?
URL url = new URL("http://androidexample.com/media/webservice/httppost.php");
// Send POST data request
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null)
{
// Append server response in string
sb.append(line + "\n");
}
text = sb.toString();
}
왜 뭐가 있는지보고 단계별 디버깅을 사용하지 계속 하시겠습니까? – ben75
안드로이드 매니페스트에' uses-permission>'을 추가 했습니까? –
PKlumpp
네, 제가 추가했습니다. – user3404539