//設定接受的檔案型別,*表示一切可以接受的
conn.setrequestproperty("accept", "*/*");
conn.setrequestproperty("connection", "keep-alive");
//todo 新新增的請求頭編碼
conn.setrequestproperty("accept-charset", "utf-8");
conn.setrequestproperty("user-agent", "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1;sv1)");
// 傳送post請求必須設定如下兩行
conn.setdooutput(true);
conn.setdoinput(true);
// 獲取urlconnection物件對應的輸出流
out = new printwriter(conn.getoutputstream());
// 傳送請求引數
out.print(param);
// flush輸出流的緩衝
out.flush();
// 定義bufferedreader輸入流來讀取url的響應
/*in = new bufferedreader(
new inputstreamreader(conn.getinputstream()));*/
//todo 新新增設定,返回編碼
in = new bufferedreader(
new inputstreamreader(conn.getinputstream(), "utf-8"));
string line;
while ((line = in.readline()) != null)
} catch (exception e)
// 使用finally塊來關閉輸出流、輸入流
finally
if (in != null)
} catch (ioexception ex)
}return result;
}
有返回值和無返回值函式
前面在定義函式時,有些函式使用了return語句,有些函式沒有使用return語句,使用return語句與不使用return語句有什麼區別呢?由前面的章節我們知道,若定義函式時沒有使用return語句,則預設返回乙個none。要返回乙個none,可以只寫乙個return,但要返回具體的數值,就需要在...
AJAX請求返回值對應解釋
xmlhttp.readystate的值及解釋 0 請求未初始化 還沒有呼叫 open 1 請求已經建立,但是還沒有傳送 還沒有呼叫 send 2 請求已傳送,正在處理中 通常現在可以從響應中獲取內容頭 3 請求在處理中 通常響應中已有部分資料可用了,但是伺服器還沒有完成響應的生成。4 響應已完成 ...
axios請求獲取到返回值
最近在學習vue,碰到乙個問題就是需要從後端獲取到某個返回值之後再執行後面的 一般呼叫axios介面都是這樣的格式。this axios.post api x xx this qs.stringify then res catch error 這樣的格式要想獲取到返回值的話,就要將 都寫在then中...