1
我正在嘗試發佈評論到網站,POST似乎沒有給出錯誤,但似乎也沒有工作。我不確定我哪裏出錯了?我稱它在一個單獨的線程Android POST發表評論到一個網站
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
HttpURLConnection conn = null;
try {
String urlString = mainUrl +"?name=" + name;
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.getOutputStream().write(comment.getBytes("UTF8"));
conn.connect();
int responseCode = conn.getResponseCode();
Log.d("Response Code: ", "" + responseCode);
} catch (Exception e) {
Log.e("POST ERROR", e.toString());
}
finally {
if (conn != null) {
conn.disconnect();
}
}
}
});
thread.start();
刷新輸出流緩衝區 – xFighter