![](/img/trans.png)
[英]How do I get a servlet container to read JSESSIONID from the query string rather than from the URL
[英]How do I access an API URL in Java (rather than python)?
如何在Java中執行此操作?
import requests
params = {
"api_key": "asdfg_54321",
"format": "json"
}
r = requests.get('https://www.parsehub.com/api/v2/projects/qwertyuiop/last_ready_run/data', params=params)
print(r.text)
我需要以JSON文件的形式訪問在線API,並且可以在Python中進行訪問,但是我需要android studio應用程序的數據,因此我必須弄清楚如何使用API密鑰訪問URL Java中的權限。
確保解析$ {PROJECT_TOKEN},$ {API_KEY}和$ {FORMAT}變量
public static void getResultOfLastReadyRun() throws IOException {
URL url = new URL("https://www.parsehub.com/api/v2/projects/${PROJECT_TOKEN}/last_ready_run/data?api_key=${API_KEY}&format=${FORMAT}");
try(Scanner sc = new Scanner(new GZIPInputStream(url.openStream()))) {
while (sc.hasNext()) {
System.out.println(sc.nextLine());
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.