0
GET 메서드 대신 POST 메서드를 알고 싶습니다. 작성 방법에 대한 값을 보냈습니다. 예를 들어 GET 예제를 찾을 수 없습니다. 배치 할 값을 보내십시오.POST 메서드를 GET 메서드로 다시 작성하는 방법은 무엇입니까?
친구들이 나에게 그것을 보여줄 수 있는지 보여 줄 수 있습니까? 네트워크에서 발견 된 가르침의
private POST()
{
HttpPost httpRequest2 = new HttpPost("ip");
List<NameValuePair> params2 = new ArrayList<NameValuePair>();
params2.add(new BasicNameValuePair("Q1","b"));
//Ready to send the value of the
try
{
httpRequest2.setEntity(new UrlEncodedFormEntity(params2, HTTP.UTF_8));
httpResponse2 = new DefaultHttpClient()
.execute(httpRequest2);
if (httpResponse2.getStatusLine().getStatusCode() == 200)
{
String strResult2 = EntityUtils.toString(httpResponse2.getEntity());
return strResult2;
}
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
GET 방법 :
나는 POST 방법을
POST 방법의 예를 작성합니다.
GET 방식의 예 : 여기
public StringGet() throws Exception {
String strResult = "";
String httpUrl = "ip";
HttpGet httpRequest = new HttpGet(httpUrl);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
strResult = EntityUtils.toString(httpResponse.getEntity());
tv.setText(strResult);
} else {
tv.setText("fail");
}
return strResult;
}
}
들으 나는 몇 가지 문제가 해결되지, HttpGet 방법으로 데이터를 전송하는 샘플 코드입니다. 은 = entity.getContent(); "is"값을 묻고 싶습니다. I 오류 메시지. 은 (는) 변수로 확인할 수 없습니다. "is ="제거가 올바르게 수행 될 수 있습니다. 그러나 시간 구현은 건너 뛰었습니다. HttpEntity entity = response.getEntity(); entity.getContent(); 수행되지 않습니다. 나는 무엇 때문에 그것을 묻는가? –
은 'is'를 InputStream 변수로 선언합니다. 나는 코드를 편집했다. –