+ Start a Discussion
David Roberts 4David Roberts 4 

No Protocol Error for HttpRequest JSON POST

The following code throws an exeption at the callout request
CALLOUT_REQUEST [35]|System.HttpRequest[Endpoint=http//:www.virtualworlds.co.uk/getParams.php, Method=POST]
and genearates the error,
"no protocol: http//:www.virtualworlds.co.uk/getParams.php".

I generate the list from custom objects and have verified that the list has entries.

Can you tell me what is wrong?


public class HelloWorld {
    public static void tryPost() {

     System.debug( 'Posting...' );
        List<licence__c> myList = new List<licence__c>();
        myList= [select Id,Name from licence__c LIMIT 20];  
        String endPoint = 'http//:www.virtualworlds.co.uk/getParams.php';
        String method = 'POST';
        //Prepare http req
        System.debug( 'New Request...' );
        HttpRequest req = new HttpRequest();
        System.debug( 'Set endpoint...' );
        String JSONString = JSON.serialize(myList);  
        System.debug( 'new Http...' );
        Http http = new Http();
        System.debug( 'Send request...' );
        HTTPResponse res = http.send(req);
        System.debug( 'Result?...' );

David Roberts 4David Roberts 4
Gone back to first principals:
Hopefully this will help others - a simple post method:

public class TestPost {

   public static void tryPost() {
    String payLoad = 'some_data=value+1&some_more_data=value+2&etc_etc';
    Http h = new Http();
    HttpRequest req = new HttpRequest();
//enter your URL
    HttpResponse res = h.send(req);
    system.debug('Res=' + res);
   } //end tryPost

} //end class TestPost