Muhammad Faisal
Muhammad Faisal

Reputation: 54

java.io.IOException: Server returned HTTP response code: 406 for URL

java.io.IOException: Server returned HTTP response code: 406 for URL: https://aa09616289afe6a25ea1f7f6fbf12073:[email protected]/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) at java.net.URL.openStream(URL.java:1045) at javaapplication9.Send_HTTP_Request2.call_me(Send_HTTP_Request2.java:33) at javaapplication9.Send_HTTP_Request2.main(Send_HTTP_Request2.java:21)

myCode:

URL url = new URL("https://aa09616289afe6a25ea1f7f6fbf12073:[email protected]/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();

Upvotes: 0

Views: 692

Answers (2)

Muhammad Faisal
Muhammad Faisal

Reputation: 54

I Done this by using restfull API. Thanks Rahkumar

OkHttpClient client = new OkHttpClient().newBuilder().build(); Request request = new Request.Builder() .url("https://mfaisal1521.myshopify.com/admin/api/2020-04/products/4517591449687.json") .method("GET", null) .addHeader("Authorization", "Basic YWEwOTYxNjI4OWFmZTZhMjVlYTFmN2Y2ZmJmMTIwNzM6c2hwcGFfZjVmZDQ3YTY1M2Q0OWQ2NmU4ODY0MzY1NzhjNTQxODc=").build();

Response response = client.newCall(request).execute();

Upvotes: 0

Rajkumar
Rajkumar

Reputation: 134

Guess some headers are missing in the request posted via java code.

Check in postman what are all the headers gets posted add the same headers in java code also (click headers/code link in Postman to view the headers gets parsed)

Upvotes: 1

Related Questions