안드로이드 개발 질문/답변
(글 수 45,052)
어플에서 HTTPPOST를 JSP로 보내서 ㅂ값을 받으려고 하는데
이렇게 하면 연결이 REFUSED 됐다고 나오는데..
이유를 아무리 찾아봐도 모르겠습니다.ㅠㅠ
hello.java
public void onClick(View v) {
// TODO Auto-generated method stub
// Declare a URL string
String uriAPI = "http://localhost/Testjsp/Testjsp.jsp";
/** Create an HTTP post connection */
HttpPost httpRequest = new HttpPost(uriAPI);
/**Post Pass variables must be running NameValuePair[] Array storage */
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", "멋진놈"));
try {
/** Makes an HTTP request request */
httpRequest.setEntity(new UrlEncodedFormEntity(params,
HTTP.UTF_8));
/** Gets the HTTP response response */
HttpResponse httpresponse = new DefaultHttpClient()
.execute(httpRequest);
/** If the status code 200 response successfully */
if (httpresponse.getStatusLine().getStatusCode() == 200) {
/** Remove the response string */
String strResponse = EntityUtils.toString(httpresponse
.getEntity());
text1.setText(strResponse);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
text2.setText(e.getMessage().toString());
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
text2.setText(e.getMessage().toString());
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
text2.setText(e.getMessage().toString());
e.printStackTrace();
}
}
Testjsp.jsp
<tr>
<td><%= request.getParameter("name") %></td>
</tr>
감사합니다. 즐거운 하루 보내세요~




주소를 로컬호스트로하면 당연히 안되죠