저는 안드로이드를 처음 접했고 이제는 안드로이드 HTTP 요청에 대한 최고의 자습서를 찾는 것에 지쳤습니다. 내가 phpServer에 이러한 매개 변수를 보내려고안드로이드에서 http 게시 요청을 보내는 방법은 무엇입니까?
,
이름 = "몇 가지 이름"
이메일 = "일부 이메일"
우리는이 작업을 수행 할 수 MainActivity.java 파일에? jar (라이브러리) 파일이 필요합니까? 모든 의견을 환영합니다. 나는이 시도
,@Override
public void onClick(View view) {
if(view == btnSubscribe){
HttpURLConnection client = null;
try {
URL url = new URL("http://www/somewebsite.com/API/SUBSCRIBE");
client = (HttpURLConnection) url.openConnection();
client.setRequestMethod("POST");
client.setRequestProperty("name","test one");
client.setRequestProperty("email","[email protected]");
client.setDoOutput(true);
OutputStream outputPost = new BufferedOutputStream(client.getOutputStream());
outputPost.flush();
outputPost.close();
client.setChunkedStreamingMode(0);
} catch(MalformedURLException error) {
showError("Handles an incorrectly entered UR");
}
catch(SocketTimeoutException error) {
showError("Handles URL access timeout");
}
catch (IOException error) {
showError("Handles input and output errors");
}finally {
if(client != null)
client.disconnect();
}
}
}
여기서 코드 ???? –
@Sahan Go [this] (http://stackoverflow.com/help/mcve) – Nisarg
@IntelliJAmiya 죄송합니다. 나를 위해 일하지 않아서 모든 코드를 정리했습니다. 이제 나는 새로운 프로젝트에 들어갔다. – Sahan