0
鏈接在瀏覽器,但不是在HttpURLConnection的工作
public class DPLoader extends AsyncTask<String, Void, String> {
Context context;
DPLoader(Context context) {
this.context = context;
}
@Override
protected String doInBackground(String... params) {
String login_url = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
try {
URL url = new URL(login_url);
HttpURLConnection httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setDoInput(true);
//此處下面我想讀,但沒有得到結果
InputStream inputstream = httpurlconnection.getInputStream();
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "iso-8859-1"));
String result = "";
String line = "";
while ((line = bufferedreader.readLine()) != null) {
result += line;
}
bufferedreader.close();
inputstream.close();
httpurlconnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "null";
}
@Override
protected void onPreExecute() {
// Toast.makeText(context, ""+ usernameEt.getText().toString(), Toast.LENGTH_SHORT).show();
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(context, ""+result, Toast.LENGTH_SHORT).show();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
圖像是我與httpurlconnection.getErrorstream()`` and with
HttpURLConnection的嘗試結果敬酒.getInputStream()我變空。 當我在瀏覽器中打開鏈接它呼應的結果,但沒有迴音結果的Android HttpURLConnection的
- 列表項
我沒有登錄到這個瀏覽器,但是這個鏈接在瀏覽器合作,以呼應的結果,但在Adnroid內 – Src7
不工作,你能告訴我什麼是響應代碼。你可以得到它如下:httpurlconnection.getResponseCode() –
錯誤403禁止 – Src7