私は現在、投稿リクエストを送信し、サーバーから json オブジェクトを取得する必要があるプロジェクトに取り組んでいます。前に、Get メソッドを使用して json オブジェクトにアクセスしました。うまくいきました。しかし、いくつかのサーバーの変更により、post メソッドに移行する必要がありました。その後、「get」メソッドから以前に取得したjsonオブジェクトが返されません。解決策を考え出すために最善を尽くしましたが、できませんでした。この問題を解決するために誰かが私を助けてくれれば、非常に感謝しています。
private AdSniperAdObjectResponse postData(String url) {
//Bundle b = new Bundle();
HttpClient httpClient = HttpClientFactory.getThreadSafeClient();
//Log.d(TAG, "url: " + url);
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept", "JSON");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("latitude", "-33.8736"));
nameValuePairs.add(new BasicNameValuePair("longitude", "151.207"));
nameValuePairs.add(new BasicNameValuePair("age", "35"));
nameValuePairs.add(new BasicNameValuePair("gender", "All"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity resEntity = httpResponse.getEntity();
if (resEntity != null) {
String resp = EntityUtils.toString(resEntity);
上記は私が使用するコードです。以前は HttpGet クラスを使用しました。HttpPost の場合、'resp' 変数は常に null です。私が何を間違えたのかわからない。