![](/img/trans.png)
[英]Getting error “java.io.IOException: Server returned HTTP response code: 406”, when calling servlet method
[英]java.io.IOException: Server returned HTTP response code: 406 for URL
java.io.IOException: Server returned HTTP response code: 406 for URL: https://aa09616289afe6a25ea1f7f6fbf12073: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@mfaisal1521.myshopify.com/admin/api/2020-04/products.json at sun.net.www.protocol. http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl. java:254) 在 java.net.URL.openStream(URL.java:1045) 在 javaapplication9. 我(Send_HTTP_Request2.java:33)在javaapplication9.Send_HTTP_Request2.main(Send_HTTP_Request2.java:21)
我的代碼:
URL url = new URL("https://aa09616289afe6a25ea1f7f6fbf12073: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@mfaisal1521.myshopify.com/admin/api/2020-04/products.json");
BufferedReader read = new BufferedReader(
new InputStreamReader(url.openStream()));
String i;
while ((i = read.readLine()) != null)
System.out.println(i);
read.close();
猜猜通過 java 代碼發布的請求中缺少一些標頭。
檢查 postman 發布的所有標題是什么 在 java 代碼中添加相同的標題(單擊 Postman 中的標題/代碼鏈接以查看標題得到解析)
我通過使用 restfull API 完成了這項工作。 謝謝拉庫馬爾
OkHttpClient 客戶端 = 新 OkHttpClient().newBuilder().build(); 請求請求 = new Request.Builder().url(" https://mfaisal1521.myshopify.com/admin/api/2020-04/products/4517591449687.json ").method(" "授權", "基本 YWEwOTYxNjI4OWFmZTZhMjVlYTFmN2Y2ZmJmMTIwNzM6c2hwcGFfZjVmZDQ3YTY1M2Q0OWQ2NmU4ODY0MzY1NzhjNTQxODc=").build();
響應響應 = client.newCall(request).execute();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.