Acess api using hava httpurlconnection

RJA
New Member
4 0 0

Hello,

 

I'm trying to access my shopify app using java httpurlconnection:

 

I tried:

 

 

 

 String urlParameters  = "-H \"X-Shopify-Access-Token: my_token\""; 
 URL url = new URL(SHOPIFY_API+"orders.json ");
        
 HttpURLConnection conn= (HttpURLConnection) url.openConnection();           
 conn.setDoOutput(true);
 conn.setRequestMethod("GET");
 conn.setRequestProperty("accept", "application/json");
 conn.setRequestProperty("X-Shopify-Access-Token",sl.getTOKEN());

        OutputStream os = conn.getOutputStream();
        os.write(urlParameters.getBytes());
        os.flush();
 
        InputStream is = null;
        
        if(conn.getResponseCode()>=200 && conn.getResponseCode()<=299) {
            is = conn.getInputStream();  
        } else {
            is = conn.getErrorStream();
        }

        BufferedReader token_data = new BufferedReader(new InputStreamReader(is));

        token_data.lines().forEach((lin) -> {
            data = lin;
            System.out.println(data);
        });
        

 

 

 

 

 

I get a 406 response code.

 

I also tried :

 

 

 

 

 

 String urlParameters  = "-H \"X-Shopify-Access-Token: my_token\""; 
 URL url = new URL(SHOPIFY_API+"orders.json " + urlParameters);
        
  HttpURLConnection conn= (HttpURLConnection) url.openConnection();           
  conn.setDoOutput(true);
  conn.setRequestMethod("GET");
  conn.setRequestProperty("accept", "application/json");

        InputStream is = null;
        
        if(conn.getResponseCode()>=200 && conn.getResponseCode()<=299) {
            is = conn.getInputStream();  
        } else {
            is = conn.getErrorStream();
        }

        BufferedReader token_data = new BufferedReader(new InputStreamReader(is));

        token_data.lines().forEach((lin) -> {
            data = lin;
            System.out.println(data);
        });

 

 

 

 

 But instead of getting my orders i get an xml:

 

 

 

<html>
<body>
<noscript>
<a href="https://accounts.shopify.com/oauth/authorize?...">Continue</a>
</noscript>

<script type="text/javascript" defer>
window.location = "https:\/\/accounts.shopify.com\/oauth\/authorize?...";
</script>
</body>
</html>

 

 

 

Can anyone help me?

Replies 0 (0)