canvas-api/src/main/java/com/instructure/canvasapi/api/compatibility_synchronous/HttpHelpers.java
/**
     * httpPost is  a bare-bones implementation for writing HTTPPost requests to the CanvasAPI.
     * It is used for the old-style synchronous calls that haven't yet been converted.
     * @param postURL
     * @param postVars
     * @param context
     * @return
     */
httpPost is  a bare-bones implementation for writing HTTPPost requests to the CanvasAPI.
It is used for the old-style synchronous calls that haven't yet been converted.
httpPost is a bare - bones implementation for writing HTTPPost requests to the CanvasAPI . It is used for the old - style synchronous calls that haven ' t yet been converted .
public static APIHttpResponse httpPost(String postURL, List<BasicNameValuePair> postVars, Context context) {
        if(context == null) {
            return new APIHttpResponse();
        }
        try {
            postURL = Masquerading.addMasqueradeId(postURL, context);
            postURL = postURL.replace(" ", "%20");
            String api_protocol = APIHelpers.loadProtocol(context);
            if(!postURL.startsWith("https://") && !postURL.startsWith("http://"))
            {
                postURL = api_protocol + "://"+APIHelpers.getDomain(context)+"/"+postURL;
            }
            HttpPost post = new HttpPost(postURL);
            String token = APIHelpers.getToken(context);
            if(token != null)
            {
                String headerValue = String.format("Bearer %s", token);
                post.addHeader("Authorization",headerValue);
            }
            HttpClient client = getHttpClient(context);
            if(postVars!=null)
                post.setEntity(new UrlEncodedFormEntity(postVars,"UTF-8"));
            HttpResponse response = client.execute(post);
            return parseLinkHeaderResponse(response);
        } catch(Exception E) {
            return new APIHttpResponse();
        }
    }
public static APIHttpResponse httpPost ( String postURL , List < BasicNameValuePair > postVars , Context context ) { if ( context == null ) { return new APIHttpResponse ( ) ; } try { postURL = Masquerading . addMasqueradeId ( postURL , context ) ; postURL = postURL . replace ( " " , "%20" ) ; String api_protocol = APIHelpers . loadProtocol ( context ) ; if ( ! postURL . startsWith ( "https://" ) && ! postURL . startsWith ( "http://" ) ) { postURL = api_protocol + "://" + APIHelpers . getDomain ( context ) + "/" + postURL ; } HttpPost post = new HttpPost ( postURL ) ; String token = APIHelpers . getToken ( context ) ; if ( token != null ) { String headerValue = String . format ( "Bearer %s" , token ) ; post . addHeader ( "Authorization" , headerValue ) ; } HttpClient client = getHttpClient ( context ) ; if ( postVars != null ) post . setEntity ( new UrlEncodedFormEntity ( postVars , "UTF-8" ) ) ; HttpResponse response = client . execute ( post ) ; return parseLinkHeaderResponse ( response ) ; } catch ( Exception E ) { return new APIHttpResponse ( ) ; } }
httpPost is  a bare-bones implementation for writing HTTPPost requests to the CanvasAPI.
httpPost is a bare - bones implementation for writing HTTPPost requests to the CanvasAPI .
//Explicit check for null. //Remove spaces from the URL //Make sure the URL begins with https://