Join our Ask A Trainer Sessions and Chat With our Experts!

403 error - JAVA 1.8

XinwangN
Rookie
0 Votes

Our system does not support java.net.http.HttpClient, so I have to use java.net.URLConnection

 

I got 403 error

403 Forbidden
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: https://authz.constantcontact.com/oauth2/default/v1/token?code={authcode}&redirect_uri={url}&grant_t...

 

Here is my Java code,

        URL url = new URL("https://authz.constantcontact.com/oauth2/default/v1/token?code="+authCode+"&redirect_uri="+redirectUri+"&grant_type=authorization_code");
        HttpURLConnection http = (HttpURLConnection)url.openConnection();
        http.setRequestMethod("POST");
        http.setDoOutput(true);
        http.setRequestProperty("Accept", "application/json");
        http.setRequestProperty("Authorization", authHeader);
        http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        http.setRequestProperty("Content-Length", "0");
       
        System.out.println(http.getResponseCode() + " " + http.getResponseMessage());

       
        StringBuffer temp = new StringBuffer();
        Scanner scan = new Scanner(http.getInputStream(), "UTF-8");
        // Scanner scan = new Scanner(http.getInputStream());
        while (scan.hasNext()) {
           temp.append(scan.nextLine());
        }
        scan.close();
           
        http.disconnect();
1 REPLY 1
Courtney_E
Moderator
0 Votes

Hello XinwangN,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

Based on our logs for your account, it looks like you may have already resolved your issue.

 

However, if you still need assistance, please feel free to contact us directly/securely via email at webservices@constantcontact.com and reference case #30215783.  

 

Within your email, please also include the API key that you are using to make the request, the full request(s) where you are receiving the response error (including URL, headers, timestamp, and request body), and the full response body so that we can so that we can better assist you in identifying the root cause of the issue.

 

Please let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up